Skip to content

Instantly share code, notes, and snippets.

@billerickson billerickson/functions.php Secret
Created Oct 25, 2018

Embed
What would you like to do?
<?php
/**
* Exclude four posts from homepage query
* @see https://www.billerickson.net/customize-the-wordpress-query/#comment-701598
*
*/
function be_homepage_query( $query ) {
if( $query->is_main_query() && $query->is_home() && ! is_admin() ) {
$exclude = get_posts( array( 'category_name' => 'category-x', 'posts_per_page' => 4, 'fields' => 'ids' ) );
$query->set( 'post__not_in', $exclude );
}
}
add_action( 'pre_get_posts', 'be_homepage_query' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.