WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Having trouble with tax_query in query_posts (2 posts)

  1. Background:

    I'm modifying the default loop in an author archive to display multiple post types with post formats enabled. I tried using a tax_query to exclude several of the formats from the query but I can't get it to work. $paged is properly defined higher up.

    Anybody see anything wrong with this code block?

    $exclude_terms = array(
    	array(
    		'taxonomy' => 'post_format',
    		'field' => 'slug',
    		'terms' => array( 'post-format-quote', 'post-format-status', 'post-format-video' ),
    		'compare' => 'NOT IN'
    	)
    );
    
    query_posts( $query_string . '&posts_per_page=10&post_type=any&paged=' . $paged . '&tax_query=' . $exclude_terms );
  2. After a bit of tinkering, I finally got it working. Big changes were namely changing 'compare' to 'operator' in tax_query and passing in the other parameters as part of the $exclude_terms array.

    $exclude_terms = array(
    	'post_type' => 'any',
    	'author' => $author_id,
    	'posts_per_page' => 10,
    	'paged' => $paged,
    	'tax_query' => array(
    		array(
    		'taxonomy' => 'post_format',
    		'field' => 'slug',
    		'terms' => array( 'post-format-link', 'post-format-status' ),
    		'operator' => 'NOT IN'
    		)
    	)
    );
    
    query_posts( $exclude_terms );

Topic Closed

This topic has been closed to new replies.

About this Topic