category_name not working (not showing up in sql query debug)

If you’re using custom taxonomy for your CPT, then you can’t use params of WP_Query that are related with built-in categories – WP won’t be able to guess what taxonomy should be queried.

So, let’s say you have a custom taxonomy called animal_type, then your query should look something like this:

$query = new WP_Query( array( 
    'post_type'         => 'animal',
    'post_status'       => 'publish',
    'orderby'           => 'title',
    'order'             => 'asc',
    'posts_per_page'    => -1,
    'tax_query'         => array(
        array( 'taxonomy' => 'animal_type', 'field' => 'slug', 'terms' => 'rottweiler' )
    ),
    'meta_query'        => $filters
) );

Notice, that I’ve also deleted this part:

'numberposts'       => -1,

There is no such parameter for WP_Query. There was parameter called showposts, but it’s deprecated.

Leave a Comment