is_object_in_term [ WordPress Function ]
| Parameters: |
|
| Uses: | |
| Returns: |
|
| Defined at: |
|
Determine if the given object is associated with any of the given terms.
The given terms are checked against the object's terms' term_ids, names and slugs. Terms given as integers will only be checked against the object's terms' term_ids. If no terms are given, determines if object is associated with any terms in the given taxonomy.
Source
<?php
function is_object_in_term( $object_id, $taxonomy, $terms = null ) {
if ( !$object_id = (int) $object_id )
return new WP_Error( 'invalid_object', __( 'Invalid object ID' ) );
$object_terms = get_object_term_cache( $object_id, $taxonomy );
if ( empty( $object_terms ) )
$object_terms = wp_get_object_terms( $object_id, $taxonomy );
if ( is_wp_error( $object_terms ) )
return $object_terms;
if ( empty( $object_terms ) )
return false;
if ( empty( $terms ) )
return ( !empty( $object_terms ) );
$terms = (array) $terms;
if ( $ints = array_filter( $terms, 'is_int' ) )
$strs = array_diff( $terms, $ints );
else
$strs =& $terms;
foreach ( $object_terms as $object_term ) {
if ( $ints && in_array( $object_term->term_id, $ints ) ) return true; // If int, check against term_id
if ( $strs ) {
if ( in_array( $object_term->term_id, $strs ) ) return true;
if ( in_array( $object_term->name, $strs ) ) return true;
if ( in_array( $object_term->slug, $strs ) ) return true;
}
}
return false;
}
?>
Examples [ wp-snippets.com ]
Top Google zoekresultaten
- Function Reference/is object in term « WordPress Codex
Description. Determines if the given object is associated with any of the given terms. The given terms are checked against the object's terms' term_ids, names ...
codex.wordpress.org - is_object_in_term | A HitchHackers guide through WordPress
Feb 12, 2011 ... function is_object_in_term( $object_id, $taxonomy, $terms = null ) { if ( !$ object_id = (int) $object_id ) return new WP_Error( 'invalid_object', __( ...
hitchhackerguide.com - is_object_in_term (WordPress Function) - WPSeek.com
WordPress lookup for is_object_in_term, a WordPress Function. wpseek.com is a WordPress-centric search tool for developers and theme authors.
wpseek.com - Issue #35: Can't make is_object_in_term() WP core function work ...
Aug 30, 2011 ... Whatever I do, I can't make the Wordpress Core function is_object_in_term return a true for the post types I create with Magic Fields. I haven't ...
github.com