WordPress.org

Ready to get started?Download WordPress

Forums

How to exclude a single category from slider (3 posts)

  1. marciajean
    Member
    Posted 2 years ago #

    Anyone know how to keep a single category of posts from showing up in a homepage JFlow slider? My choices in the theme are to select All Categories to display, or to select a single category. I want to select all BUT ___.

    I have tried to exclude in the slider.php them by category number but it's not working.

    <?php $recent = new WP_Query("cat=" .ot_option('slider_cat&exclude=21,209,73'). "&showposts=" .ot_option('slider_num') ); while($recent->have_posts()) : $recent->the_post();?>

  2. wspencer
    Member
    Posted 2 years ago #

    If you added the 'exclude=21,209,73' there, then I think I know the solution.

    Change the code to this...

    <?php $recent = new WP_Query("cat=" .ot_option('slider_cat'). ",-21,-209,-73&showposts=" .ot_option('slider_num') ); while($recent->have_posts()) : $recent->the_post();?>

    Not having looked at the plugins code, I'm guessing the plugin has an options page for category IDs, which is saved in the variable ot_option['slider_cat']

    Since that variable should just be a string of numbers, all you should have to do is add ,-21,-209,-73 after the .ot_option('slider_cat')."

    By adding "exclude=21,209,73" inside the ot_option variable, it will break your query.

    Hopefully that works for you!

  3. Nate Reist
    Member
    Posted 2 years ago #

    You could also accomplish this by adding the tax_query parameter to the WP_Query arguments

    See http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters

    Using the operator argument you can specify NOT IN example below:

    'tax_query' => array( 'taxonomy' => %tax_name%, 'field' => 'id', 'terms' => %terms_string _or_array%, 'operator' => 'NOT IN' )

Topic Closed

This topic has been closed to new replies.

About this Topic