You appear to be a bot. Output may be restricted
Description
Exclude featured posts from the home page blog query.
Filter the home page posts, and remove any featured post ID's from it. Hooked onto the 'pre_get_posts' action, this changes the parameters of the query before it gets any posts.
Usage
$WP_Query = Featured_Content::pre_get_posts( $query );
Parameters
- $query
- ( WP_Query ) required – WP_Query object.
Returns
WP_Query Possibly-modified WP_Query.
Source
File name: twentyfourteen/inc/featured-content.php
Lines:
1 to 30 of 30
public static function pre_get_posts( $query ) { // Bail if not home or not main query. if ( ! $query->is_home() || ! $query->is_main_query() ) { return; } // Bail if the blog page is not the front page. if ( 'posts' !== get_option( 'show_on_front' ) ) { return; } $featured = self::get_featured_post_ids(); // Bail if no featured posts. if ( ! $featured ) { return; } // We need to respect post IDs already in the exclude list. $post__not_in = $query->get( 'post__not_in' ); if ( ! empty( $post__not_in ) ) { $featured = array_merge( (array) $post__not_in, $featured ); $featured = array_unique( $featured ); } $query->set( 'post__not_in', $featured ); }