[英]I have query to retrieve all posts in wordpress but how can i check the condition for post meta_key =“develop” and meta_value='anything'
SELECT DISTINCT date(p.post_date) as post_date
FROM $wpdb->posts p
LEFT JOIN $wpdb->postmeta pm ON p.ID = pm.post_id
WHERE p.post_status='publish'
AND p.post_type IN ('%s')
ORDER BY p.post_date DESC
Here it reads all dates of the posts. 它在这里读取帖子的所有日期。 My problem is that query should exclude the posts which has meta_value(it can be anything) of which meta_key="develop" . 我的问题是查询应排除具有meta_value(可以是任何东西)的帖子,其中meta_key =“ develop”。 How can i write the query for that ? 我该如何编写查询?
I feel it will be in this form for wp_query 我觉得它将以wp_query的这种形式出现
$args[ 'meta_query' ]= array (
'relation'= >' AND ',
array (
'key' = > 'respect'
),
array (
'key' => 'develop',
'compare' => 'NOT EXISTS'
)
);
$query = new Wp_query($args);
So you're trying to get all posts that don't have a meta key equal to "develop"? 因此,您正在尝试获取所有不具有等于“ develop”的meta键的帖子?
You could do this: 您可以这样做:
$query = new WP_Query( array(
'meta_key' => 'develop',
'meta_compare' => 'NOT EXISTS'
) );
Also, see this note from the Codex if you're using a version of Wordpress less than 3.9: 另外,如果您使用的Wordpress版本低于3.9,请从食典中查看此注释:
"(Note: Due to bug #23268, value is required for NOT EXISTS comparisons to work correctly prior to 3.9. You must supply some string for the value parameter. An empty string or NULL will NOT work. However, any other string will do the trick and will NOT show up in your SQL when using NOT EXISTS. Need inspiration? How about 'bug #23268'.)" “(注意:由于错误#23268,在3.9之前,NOT EXISTS比较必须正确使用值。您必须为value参数提供一些字符串。空字符串或NULL将不起作用。但是,任何其他字符串都可以技巧,并且在使用NOT EXISTS时不会在您的SQL中显示。需要灵感吗?“错误#23268”如何。)”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.