I have the following query setup to pull videos from a custom post type by category:

$cat_name = single_cat_title('', FALSE);

$videos = new WP_Query(array(
    'post_type' => 'video',
    'tax_query' => array(
        'taxonomy' => 'category',
        'field' => 'name',
        'terms' => $cat_name
    'orderby' => 'date',
    'post_status' => 'publish',
    'order' => 'DESC',
    'posts_per_page' => -1

When I echo the $cat_name variable, I'm getting the correct category name. However, when I output the request for the query, what I'm getting is:

SELECT wp_posts.* 
FROM wp_posts 
WHERE 1=1 
AND ( 0 = 1 ) 
AND wp_posts.post_type = 'video' 
AND ((wp_posts.post_status = 'publish')) 
GROUP BY wp_posts.ID 
ORDER BY wp_posts.post_date DESC

With no reference to the tax_query.

Can anyone see what I'm doing wrong that is not triggering the tax query portion of the query?


  • Why do you have 2 arrays in tax_query part ? The 2 strange parts are "1=1" and "0=1". Looking at youre query, they must map to "tax_query" and "posts_per_page". Be sure you use the right syntaxe for those 2 items... – Random May 6 '16 at 12:33
  • The tax_query parameter is an array of arrays: codex.wordpress.org/Class_Reference/…, this is why I wrote my code that way. The second query is what WordPress is outputting... it's not something I'm writing explicitly. – Yazmin May 6 '16 at 12:36
  • Yeah, I understand you didn't write the 2nd one, but you see there which parameters are well interpreted, and which are not. The 2 only missing parameters are "tax_query" and "posts_per_page", so the strange generated part must come from those 2 fields. What if you remove "posts_per_pages" ? – Random May 6 '16 at 12:39
  • Working on that @Random... – Yazmin May 6 '16 at 12:45
  • 1
    Never use term names in a tax_query, there is a known issue which I have explained in the post I marked as duplicate. You should use another method to either get the term slug or the term ID and then pass that to the tax_query – Pieter Goosen May 6 '16 at 12:45