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
-
Sorry, I neglected to format that query above as Code:
<?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 ); ?> -
Hi there,
If I can ask, what site is this for? We can’t offer PHP support here in the WordPress.com forums as this is where we support free sites (which do not have access to source code), but I can get you pointed in the right direction to get the help you need!
Thanks for the additional info!
-
- The topic ‘WP_Query, Taxonomy, list of attached items to a Term, sorted’ is closed to new replies.