-
gunbunnysouljaParticipant
Could you possibly help me out with hiding a particular category from the front page, except for those on the slider via sticky?
I am currently using $query->set( ‘post__not_in’, get_option( ‘sticky_posts’ ) ); to hide duplicates, which works great for that purpose.
Daniel TaraKeymasteryou can use the
category__not_in
parameter just as you usepost__not_in
.gunbunnysouljaParticipantDaniel, thanks for the reply. Could you possible elaborate a little more since I’m not really good with code. Do I modify that part of the existing code, or write this code in addition to what is already there.
The category that I want to take off the front page but keep on the slider is category 29.
Thanks so much!
Daniel TaraKeymasterYou need to make this call:
$query->set( ‘category__not_in’, array( 29 ) );
gunbunnysouljaParticipantDaniel,
Thanks again so much. Where do I insert that? Can I keep the existing function code of $query->set( ‘post__not_in’, get_option( ‘sticky_posts’ ) );
I tried that code before but it keeps breaking, so I’m assuming I’m putting it in the wrong area, or its conflicting somewhere.
gunbunnysouljaParticipantTo clarify, do I need to make an entirely new function call?
This is what I have:
function esplanade_ignore_sticky_posts( $query ) {
global $wp_the_query;
if( ( $wp_the_query === $query ) && $query->is_home() && esplanade_get_option( ‘slider’ ) )
$query->set( ‘post__not_in’, get_option( ‘sticky_posts’ ) );
}
endif;gunbunnysouljaParticipantTrying this:
function exclude_category($query) {
if ( $query->is_home ) {
$query->set(‘category__not_in’, ’29’);
}
return $query;
}
add_filter(‘pre_get_posts’, ‘exclude_category’);gunbunnysouljaParticipantMy code above didn’t work, as it hid from the slider too, as well as somehow now showing categories already being hidden by a plugin.
gunbunnysouljaParticipantI should note, I did include array on the actual code, so you can disregard me missing it above.
gunbunnysouljaParticipantAlmost every code I do breaks the site. I must be doing the function structure wrong.
I have also tried:
function exclude_category($query) {
if ( $query->is_home ) {
$query->set( ‘category__not_in’, array( 29 ) );
}
return $query;
}
add_filter(‘pre_get_posts’, ‘exclude_category’);
remove_filter(‘pre_get_posts’, ‘exclude_category’);as well as other variations. Any help would be greatly appreciated!
gunbunnysouljaParticipantFinally figured it out! I wrapped this into the existing function:
if( ( $wp_the_query === $query ) && $query->is_home() && esplanade_get_option( ‘slider’ ) )
$query->set( ‘cat’, -29 );So the entire function looks like:
function esplanade_ignore_sticky_posts( $query ) {
global $wp_the_query;
if( ( $wp_the_query === $query ) && $query->is_home() && esplanade_get_option( ‘slider’ ) )
$query->set( ‘post__not_in’, get_option( ‘sticky_posts’ ) );
if( ( $wp_the_query === $query ) && $query->is_home() && esplanade_get_option( ‘slider’ ) )
$query->set( ‘cat’, -29 );
}
endif;add_action( ‘pre_get_posts’, ‘esplanade_ignore_sticky_posts’ );
You must be logged in to reply to this topic.