WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] "tax_query" parameter not working with WP_Query (2 posts)

  1. farneman
    Member
    Posted 2 years ago #

    I have a custom post type called 'episode'. Attached to 'episode' I have a custom taxonomy called 'video_type' that contains two terms: "bonus-footage" and "episode"; "episode" contains two child terms "season-1" and "season-2" (other seasons will be added in the future). I want to grab only the most recent post of the 'episode' type but not include any posts from the 'bonus-footage' term. Below is the code I'm using for this:

    <?php
    $some_args = array(
    	'tax_query' => array(
                'taxonomy' => 'video_type',
                'terms' => 'bonus-footage',
                'field' => 'slug',
    	    'include_children' => true,
                'operator' => 'NOT IN'
    	),
    	'posts_per_page' => 1,
    	'post_type' => 'episode',
    );
    
    $s = new WP_Query( $some_args );
    
    if ( $s->have_posts() ) : $s->the_post();
    	// Do something with this post.
    endif;
    ?>

    The query works as expected if a post in one of the 'season' terms is the newest, but if a post in "bonus-footage" is the newest, then it's loading that one. In other words my "tax_query" parameters appear to have no affect on the query. Am I not formatting the "tax_query" properly or am I missing something else?

    I've also tried setting "tax_query" as below:

    'tax_query' => array(
                'taxonomy' => 'video_type',
                'terms' => 'episode',
                'field' => 'slug',
    	    'include_children' => true,
                'operator' => 'IN'
    	),

    but I'm still getting the same result.

  2. farneman
    Member
    Posted 2 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic