Widget Excluding Posts Homepage. Possible?
-
I’m writing a sidebar widget plugin that scans posts in a selected category for embedded YouTube videos, and displays the first one found using oEmbed.
Works great, but I’d like to ensure that the displayed post does not also appear on the Homepage.
To do that, I tried adding
// Hide category from Homepage if option set add_filter( 'pre_get_posts', function( $query ) { if( $instance[ 'excludeCategory' ] == 'on' ) { if( $query->is_home ) $query->set( 'category__not_in', array( $instance[ 'category' ] ) ); } return $query; } );
to the constructor function of my plugin.
This doesn’t work, and I suspect I know why. The main query that retrieves the posts in the primary loop must run before the widget is able to modify it.
Am I right on this, and if so, is there any way to get this to work, or will I have to build a separate non-widget plugin to be able to achieve what I want?
Cheers,
a|x
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Widget Excluding Posts Homepage. Possible?’ is closed to new replies.