0

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

1 Answer 1

0

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.

3
  • So close! I added 'post_type' => 'biblio' to my query, but it still results in 0 posts. Thinking...
    – Mark Cyzyk
    Commented Apr 27, 2022 at 22:15
  • I also tried 'post_type' => 'any'. Still no joy.
    – Mark Cyzyk
    Commented Apr 28, 2022 at 12:57
  • Must be something else wrong with my query. This retreives "biblio" posts: 'post_type' => 'biblio', 'posts_per_page' => 10
    – Mark Cyzyk
    Commented Apr 28, 2022 at 14:03

Not the answer you're looking for? Browse other questions tagged or ask your own question.