Smarter Navigation
[resolved] Trying to exclude categories... using CPT (9 posts)

  1. Design Dude
    Posted 4 years ago #

    I'm trying to exclude certain categories using smarter navigation, but I can't seem to get things to work. First I had to be able to consolidation the categories across regular post types and CPTs. I used code from http://wordpress.org/support/topic/custom-post-type-tagscategories-archive-page?replies=40 which seems to work fine. But when I indicate which category IDs I would like to exclude, it does not exclude them. Am I doing something wrong, or does this plugin not support exclusion of categories?


  2. scribu
    Plugin Author

    Posted 4 years ago #

    If you want to exclude categories, exclude them from the initial archive page:

    If a user goes to http://yoursite.com/category/parent/ and you make it so that he doesn't see posts in the child-excluded category, for example, he won't see them when using the links generated by Smarter Navigation either.

    Here's how you can do that:


  3. Design Dude
    Posted 4 years ago #

    Hmmm, I think that there might be a misunderstanding, or else I don't understand WP/php well enough to execute your answer above.
    Here's what I'm trying to do:

    next_post_smart('%link', '<', TRUE, '4');
    previous_post_smart('%link', '>', TRUE, '4');

    So I want Smarter Navigation to navigate through posts of a referrer category, but I want to exclude any posts from the post ID '4' category.

  4. scribu
    Plugin Author

    Posted 4 years ago #

    No, I understood what you're trying to achieve and the way to do it is through WP_Query, since that's what the Smarter Navigation plugin looks at.

    You do have to understand WordPress fairly well to do it, though. Maybe this presentation will help:


  5. Design Dude
    Posted 4 years ago #

    I'll take a look thanks. After thinking more about what you said it sunk in.
    Now, I just need to figure out how to use queries.

  6. Design Dude
    Posted 4 years ago #

    Shouldn't this work using below? I tried and it did not...
    <?php query_posts($query_string . '&cat=-4'); ?>

  7. scribu
    Plugin Author

    Posted 4 years ago #

    No, because SN collects the query vars before the template is loaded. It has to because cookies can't be set once any output is sent to the browser.

  8. Design Dude
    Posted 4 years ago #

    Got it working! Thanks. So simple once I got my head around it.

  9. Marlus Araujo
    Posted 3 years ago #

    hello @scribu, as you described above, I created a WP_query inside my taxonomy-arquivos.php template with include_children set to false:

    $args = array(
    		'orderby' => ($term->parent) ? 'date' : 'rand',
    		'post_status' => 'publish',
    		'tax_query' => array(
    				'taxonomy' => 'arquivos',
    				'field' => 'slug',
    				'terms' => get_query_var( 'term' ),
    				'include_children' => false
    	$the_query = new WP_Query( $args );
    	while( $the_query->have_posts() ) {

    But when I click on a post and navigate, I still get some posts of a children taxonomy.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Smarter Navigation
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic