Random WordPress Function

Learn about a new WordPress function every day!


Function Signature:

wp_term_is_shared

Function Description:

Determines whether a term is shared between multiple taxonomies.

Function Examples:

⚠️ Examples below are generated with GPT-3 once every hour. Do not take them too seriously.
Consider them as some extra input in your learning process - reason about them. Will it work? What could fail?
// Example 1: Check if a term is shared across multiple taxonomies
$term_id = 5;
$taxonomy1 = 'category';
$taxonomy2 = 'post_tag';
$is_shared = wp_term_is_shared($term_id, array($taxonomy1, $taxonomy2));
if ($is_shared) {
    echo 'The term with ID 5 is shared between categories and tags.';
} else {
    echo 'The term with ID 5 is not shared between categories and tags.';
}
// Example 2: Avoiding errors when checking if a term is shared
$term_id = 10;
$taxonomy1 = 'category';
$taxonomy2 = 'post_tag';
if (taxonomy_exists($taxonomy1) && taxonomy_exists($taxonomy2)) {
    $is_shared = wp_term_is_shared($term_id, array($taxonomy1, $taxonomy2));
    if ($is_shared) {
        echo 'The term with ID 10 is shared between categories and tags.';
    } else {
        echo 'The term with ID 10 is not shared between categories and tags.';
    }
} else {
    echo 'One or both of the taxonomies do not exist.';
}
// Example 3: Handling the case when the term ID does not exist
$term_id = 15;
$taxonomy1 = 'category';
$taxonomy2 = 'post_tag';
if (term_exists($term_id, $taxonomy1) || term_exists($term_id, $taxonomy2)) {
    $is_shared = wp_term_is_shared($term_id, array($taxonomy1, $taxonomy2));
    if ($is_shared) {
        echo 'The term with ID 15 is shared between categories and tags.';
    } else {
        echo 'The term with ID 15 is not shared between categories and tags.';
    }
} else {
    echo 'The term with ID 15 does not exist in either of the taxonomies.';
}