Excl. cats using pre_get_posts
-
I’ve written a quick function to exclude a category from my main query loop, however… whenever I include this it messes up the order of the loop so that things are reverse chronological – using the set ‘order’ doesn’t seem to fix it either (see example below). Anyone else come across this and know how to resolve?
I do not want to use the query_posts() function – in fact this gives exactly the same result.
function exclude_category( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $idObj = get_category_by_slug('content-large-fancy-box'); $lfb_cat_id = $idObj->term_id; $query->set( 'cat', '-'.$lfb_cat_id ); $query->set( 'orderby', 'date'); $query->set( 'order', 'DESC'); } } add_action( 'pre_get_posts', 'exclude_category' );
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Excl. cats using pre_get_posts’ is closed to new replies.