WordPress.org

Ready to get started?Download WordPress

Forums

posts_not_in by CATEGORY (4 posts)

  1. ngoodfellow
    Member
    Posted 1 year ago #

    I'm trying to figure this one out and having some issues:

    Trying to filter my posts by category so that a certain category is not displayed in the list
    this is in the Showcase Template for twentyeleven theme

    [ Moderator Note: Please post code or markup snippets between backticks or use the code button. ]

    // Display our recent posts, showing full content for the very latest, ignoring Aside posts.
    					$recent_args = array(
    						'order' => 'DESC',
    						'post__not_in' => get_category(15),
    						'tax_query' => array(
    							array(
    								'taxonomy' => 'post_format',
    								'terms' => array( 'post-format-aside', 'post-format-link', 'post-format-quote', 'post-format-status' ),
    								'field' => 'slug',
    								'operator' => 'NOT IN',
    							),
    						),
    						'no_found_rows' => true,
    					);
    
    This is the code I think I need to change:
       'post__not_in' => get_category(15),

    This setting give me an error that it is not in an array, not sure how to fix that.
    Thanks!

  2. Andrew Bartel
    Member
    Posted 1 year ago #

    Just put the number: 'post__not_in' => 15,

  3. ngoodfellow
    Member
    Posted 1 year ago #

    I resolved this issue with the following:

    'cat' => -$cat,

    This displayed posts that are NOT IN (negative before hand) the current category

    Seems to be working fine!

  4. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    there is also the 'category__not_in' parameter;

    'category__not_in' => array(15)

    http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.