I'm trying to search posts by a taxonomy value, the problem is that the query doesn't return anything, this is my code so far:
$args = array(
'post_type' => 'zoacres-property',
'post_status' => 'publish',
'posts_per_page' => 10,
'order' => 'DESC',
'tax_query' => array(
array(
'taxonomy' => 'property-region',
'field' => 'name',
'terms' => array('Lazio (IT)'),
'operator' => 'IN'
)
)
);
$query = new WP_Query($args);
This is the post record stored in the db:
wp_posts
id | post_title | post_type
30081 test zoacres-property
the taxonomy property-region
have that content:
wp_terms
term_id | name
62 Lazio (IT)
wp_term_taxonomy
term_taxonomy_id | term_id | taxonomy
62 62 property-region
wp_term_relationships
object_id | term_taxonomy
30081 62
why my query isn't returning anything?
UPDATE
output of $query->request
:
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND (
0 = 1
) AND wp_posts.post_type = 'zoacres-property' AND ((wp_posts.post_status = 'publish')) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 10"
if I change the query as follows:
$args = array(
'post_type' => 'zoacres-property',
'post_status' => 'publish',
'posts_per_page' => 10,
'order' => 'DESC',
'tax_query' => array(
array(
'taxonomy' => 'property-region',
'field' => 'term_id',
'terms' => 2
)
)
);
I get as output:
"SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE 1=1 AND (
wp_term_relationships.term_taxonomy_id IN (2)
) AND wp_posts.post_type = 'zoacres-property' AND ((wp_posts.post_status = 'publish')) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 10"
where 2
is the id of Lazio (IT)
, the post is published with that taxonomy
linked. No idea why this doesn't return anything
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745002147a4605561.html
评论列表(0条)