Ticket #12526: has_term.2.diff
| File has_term.2.diff, 3.8 KB (added by ptahdunbar, 3 years ago) |
|---|
-
wp-includes/category-template.php
251 251 * @param int|post object Optional. Post to check instead of the current post. @since 2.7.0 252 252 * @return bool True if the current post is in any of the given categories. 253 253 */ 254 function in_category( $category, $_post = null ) { 255 if ( empty( $category ) ) 256 return false; 257 258 if ( $_post ) { 259 $_post = get_post( $_post ); 260 } else { 261 $_post =& $GLOBALS['post']; 262 } 263 264 if ( !$_post ) 265 return false; 266 267 $r = is_object_in_term( $_post->ID, 'category', $category ); 268 if ( is_wp_error( $r ) ) 269 return false; 270 return $r; 254 function in_category( $category, $post = null ) { 255 return has_category( $category, $post ); 271 256 } 272 257 273 258 /** … … 969 954 } 970 955 971 956 /** 972 * Check if the current post has any of given tags.957 * Check if the current post has any of given categories. 973 958 * 974 * The given tags are checked against the post's tags' term_ids, names and slugs. 975 * Tags given as integers will only be checked against the post's tags' term_ids. 976 * If no tags are given, determines if post has any tags. 959 * @since 3.0.0 977 960 * 978 * 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) 979 * Prior to v2.7, this function could only be used in the WordPress Loop. 980 * As of 2.7, the function can be used anywhere if it is provided a post ID or post object. 961 * @uses is_object_in_term() 962 * @see has_term() 981 963 * 964 * @param string|int|array $tag Optional. The category name/category_id/slug or array of them to check for. 965 * @param int|post object Optional. Post to check instead of the current post. 966 * @return bool True if the current post has any of the the given categories (or any category, if no category specified). 967 */ 968 function has_category( $category = '', $post = null ) { 969 return has_term( $category, 'category', $post ); 970 } 971 972 /** 973 * Check if the current post has any of given tags. 974 * 982 975 * @since 2.6.0 983 976 * 984 977 * @uses is_object_in_term() 978 * @see has_term() 985 979 * 986 * @param string|int|array $tag Optional. The tag name/term_id/slug or array of them to check for. 980 * @param string|int|array $tag Optional. The tag name/tag_id/slug or array of them to check for. 981 * @param int|post object Optional. Post to check instead of the current post. 982 * @return bool True if the current post has any of the the given tags (or any tag, if no tag specified). 983 */ 984 function has_tag( $tag = '', $post = null ) { 985 return has_term( $tag, 'post_tag', $post ); 986 } 987 988 989 /** 990 * Check if the current post has any of given terms. 991 * 992 * The given terms are checked against the post's terms' term_ids, names and slugs. 993 * Terms given as integers will only be checked against the post's terms' term_ids. 994 * If no terms are given, determines if post has any terms. 995 * 996 * @since 3.0.0 997 * 998 * @uses is_object_in_term() 999 * 1000 * @param string|int|array $tag Optional. The term name/term_id/slug or array of them to check for. 987 1001 * @param int|post object Optional. Post to check instead of the current post. @since 2.7.0 988 1002 * @return bool True if the current post has any of the the given tags (or any tag, if no tag specified). 989 1003 */ 990 function has_tag( $tag = '', $_post = null ) { 991 if ( $_post ) { 992 $_post = get_post( $_post ); 993 } else { 994 $_post =& $GLOBALS['post']; 995 } 1004 function has_term( $term = '', $taxonomy = '', $post = null ) { 1005 if ( $post ) 1006 $post = get_post( $post ); 1007 else 1008 $post =& $GLOBALS['post']; 996 1009 997 if ( !$ _post )1010 if ( !$post ) 998 1011 return false; 999 1012 1000 $r = is_object_in_term( $ _post->ID, 'post_tag', $tag);1013 $r = is_object_in_term( $post->ID, $taxonomy, $term ); 1001 1014 if ( is_wp_error( $r ) ) 1002 1015 return false; 1003 1016 return $r; 1004 1017 } 1005 1006 1018 ?> 1007 No newline at end of file