[wp-trac] [WordPress Trac] #34513: is_single() or is_singular() are not running filters on the queried object
WordPress Trac
noreply at wordpress.org
Fri Oct 30 22:25:29 UTC 2015
#34513: is_single() or is_singular() are not running filters on the queried object
--------------------------+----------------------
Reporter: LindsayBSC | Owner:
Type: defect (bug) | Status: closed
Priority: normal | Milestone:
Component: Query | Version: 4.3.1
Severity: normal | Resolution: invalid
Keywords: close | Focuses:
--------------------------+----------------------
Changes (by johnbillion):
* status: new => closed
* resolution: => invalid
* milestone: Awaiting Review =>
Comment:
The issue isn't with `is_singular()` or `is_single()` - the issue is that
your conditional logic affects all queries on the page instead of just the
main query.
The template conditional functions refer to the main query (ie. the main
loop), but you're not accounting for the fact that not every query is the
main query.
Your conditional logic should use `is_main_query()` and should look
something like this:
{{{
function my_add_custom_content( $title) {
if ( is_main_query() && is_singular( 'events' ) ):
$postID = get_the_ID();
$html = '<a href="#" class="goingLink setGoing"
id="'.$postID.'" data-value="'. $postID .'">I\'m Going</a><div id="fb-
root"></div>';
$title .= $html;
endif;
return $title;
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/34513#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list