WordPress.org

Make WordPress Core

Ticket #12526: has_taxonomies.diff

File has_taxonomies.diff, 2.1 KB (added by ptahdunbar, 4 years ago)
  • wp-includes/category-template.php

     
    964964 * 
    965965 * @since 2.6.0 
    966966 * 
    967  * @uses is_object_in_term() 
     967 * @see has_taxonomy() 
    968968 * 
    969969 * @param string|int|array $tag Optional. The tag name/term_id/slug or array of them to check for. 
    970970 * @param int|post object Optional.  Post to check instead of the current post. @since 2.7.0 
    971971 * @return bool True if the current post has any of the the given tags (or any tag, if no tag specified). 
    972972 */ 
    973973function has_tag( $tag = '', $_post = null ) { 
     974        return has_taxonomy( $tag, 'post_tag', $_post ); 
     975} 
     976 
     977/** 
     978 * Check if the current post has any of given taxonomies. 
     979 * 
     980 * The given tags are checked against the post's tags' term_ids, names and slugs. 
     981 * Taxonomies given as integers will only be checked against the post's taxonomies' term_ids. 
     982 * If no tags are given, determines if post has any taxonomies. 
     983 * 
     984 * Prior to v2.7 of WordPress, tags given as integers would also be checked against the post's tags' names and slugs (in addition to term_ids) 
     985 * Prior to v2.7, this function could only be used in the WordPress Loop. 
     986 * As of 2.7, the function can be used anywhere if it is provided a post ID or post object. 
     987 * 
     988 * @since 3.0.0 
     989 * 
     990 * @uses is_object_in_term() 
     991 * 
     992 * @param string|int|array $tag Optional. The tag name/term_id/slug or array of them to check for. 
     993 * @param string $taxonomy Optional. The taxonomy to check for. 
     994 * @param int|post object Optional. Post to check instead of the current post. 
     995 * @return bool True if the current post has any of the the given tags (or any tag, if no tag specified). 
     996 */ 
     997function has_taxonomy( $tag = '', $taxonomy = '', $_post = null ) { 
    974998        if ( $_post ) { 
    975999                $_post = get_post( $_post ); 
    9761000        } else { 
     
    9801004        if ( !$_post ) 
    9811005                return false; 
    9821006 
    983         $r = is_object_in_term( $_post->ID, 'post_tag', $tag ); 
     1007        $r = is_object_in_term( $_post->ID, $taxonomy, $tag ); 
    9841008        if ( is_wp_error( $r ) ) 
    9851009                return false; 
    9861010        return $r;