[wp-trac] [WordPress Trac] #37042: Additional filter for has_category function
WordPress Trac
noreply at wordpress.org
Tue Jun 7 09:01:52 UTC 2016
#37042: Additional filter for has_category function
-----------------------------+------------------------------
Reporter: jakubbis | Owner:
Type: feature request | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 4.5.2
Severity: normal | Resolution:
Keywords: | Focuses:
-----------------------------+------------------------------
Comment (by jakubbis):
We can obtain this goal e.g. in this way:
{{{#!php
<?php
function has_term( $term = '', $taxonomy = '', $post = null ) {
$default_args = array( $term, $taxonomy, $post );
$args = apply_filters( 'has_term', array( $term,
$taxonomy, $post ) );
$args = array_merge( $default_args, $args );
$term = $args[0];
$taxonomy = $args[1];
$post = $args[2];
$post = get_post($post);
if ( !$post )
return false;
$r = is_object_in_term( $post->ID, $taxonomy, $term );
if ( is_wp_error( $r ) )
return false;
return $r;
}
}}}
''has_term'' filter will allow to transform $term value before proceeding
actual logic.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/37042#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list