WP_Query, Taxonomy, list of attached items to a Term, sorted

I have a Taxonomy, “Genre”. “Genre” has a Term, “advert”. I want my taxomomy template to grab all Custom Posts attached to that term, sort them by my last_name, first_name, short_title Custom Fields, and output.

But my custom query is returning 0 posts! I would love to get another set of eyes on this. I’m missing something!

?php
$args = array(
    'tax_query' = array(
        array(
            'taxonomy' = 'genre',
            'terms'    = array( 'advert' )
        )
    ),
        'meta_query'      = array(
            'relation'           = 'AND',
            'last_name_clause'   = array(
                'key'     = 'last_name',
                'compare' = 'EXISTS',
            ),
            'first_name_clause'  = array(
                'key'     = 'first_name',
                'compare' = 'EXISTS',
            ),
            'short_title_clause' = array(
                'key'     = 'short_title',
                'compare' = 'EXISTS',
            ),
        ),
        'orderby'        = array(
            'last_name_clause'   = 'ASC',
            'first_name_clause'  = 'ASC',
            'short_title_clause' = 'ASC',
        ),
    );
$newQuery = new WP_Query( $args );
?

Best regards,

Mark

Topic taxonomy sort Wordpress

Category Web


You're looking for custom posts, but don't define post_type in your query, which means it will default to the core post post type only.

You need to incorporate

'post_type' => 'my-cpt'

into your query.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.