[英]meta_query not working in wp_query
我的帖子类型是product
。 当我的print_r
是array([0] => featured)时,我使用一个带有meta key
为ht_featured
meta值的复选框字段。
我的WP_Query:
$the_query = new WP_Query(
'post_type' => 'product',
'showposts' => 12,
'meta_query' => array(
array(
'key' => 'ht_featured',
'value' => array('featured'),
'compare' => 'IN'
)
)
);
它没有显示任何帖子。 我尝试使用value => 'featured'
和'compare' => 'EXISTS'
但它不起作用。
WP_query需要在数组中传递。 使用以下代码,让我知道是否有问题。
$the_query = new WP_Query (array (
'post_type' => 'product',
'showposts' => 12,
'meta_query' => array(
array(
'key' => 'ht_featured',
'value' => array('featured'),
'compare' => 'IN'
)
)
));
您可以在wordpress论坛上参考讨论:
http://wordpress.org/support/topic/how-to-wp_query-meta_query-value-string-contain-in-key-string
当所有这些参数都应包含在数组中时,会将它们作为单独的参数传递给WP_Query。
$the_query = new WP_Query( array(
'post_type' => 'product',
'showposts' => 12,
'meta_query' => array(
array(
'key' => 'ht_featured',
'value' => array('featured'),
'compare' => 'IN',
),
),
) );
您能否阐明您对复选框的观点? 我建议您在保存产品时仅将“ ht_featured”更新为“是”或“否”。 然后将元查询中的“值”更改为“是”,然后删除“比较”。
您确定没有php错误? 我认为WP_Query需要在数组中传递
$the_query = new WP_Query(
array(
'post_type' => 'product',
'showposts' => 12,
'meta_query' => array(
array(
'key' => 'ht_featured',
'value' => array('featured'),
'compare' => 'IN'
)
)
));
在使用函数get_posts()而不是创建新的WP_Query之前,我遇到了类似的问题。 看看是否有帮助...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.