Any suggestions on how to get the title of the first custom post type of ‘property’ with the term ‘Locked’ in the taxonomy ‘status’?
$args = array(
'post_type' => 'property',
'tax_query' => array(
array(
'taxonomy' => 'status',
'field' => 'slug',
'terms' => 'locked'
)
)
);
$your_query = new WP_Query( $args );
while ( $your_query->have_posts() ) {
$your_query->the_post();
$the_title = get_the_title(); // variable $the_title now holds your title
}
What I really need is a way that I can query by multiple terms and taxonomies.
$args = array(
'post_type' => 'property',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'status',
'field' => 'slug',
'terms' => 'locked'
),
array(
'taxonomy' => 'color',
'field' => 'slug',
'terms' => 'blue'
)
)
);
$your_query = new WP_Query( $args );
Related Reading:
http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters