简体   繁体   English

我有查询来检索wordpress中的所有帖子,但是如何检查发布条件meta_key =“ develop”和meta_value ='anything'

[英]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.

相关问题 如果WordPress中的meta_key = x和meta_value = y,如何显示图像? - How can I display an image if the meta_key=x AND meta_value=y in WordPress? 通过在Wordpress中由meta_key和meta_value标识的自定义查询字符串来检索发布 - Retrieve Post by Custom Query String identified by meta_key and meta_value in Wordpress 使用带有Ajax的select元素按WordPress中的一个meta_key和两个meta_value过滤帖子 - Filter posts by one meta_key and two meta_value in WordPress using a select element with Ajax 如何通过meta_value和meta_key检索meta_values的结果? - How to retrieve results of meta_values by meta_value and meta_key? WPDB查询-根据_meta_key返回meta_value - WPDB Query - Return meta_value based on _meta_key 构造MySQL查询(meta_key / meta_value表) - Construct MySQL query ( meta_key/meta_value table) WP->查询从meta_value和meta_key获取自定义帖子ID - WP->Query get Custom Post ID from meta_value & meta_key 通过高级自定义字段(meta_key和meta_value)获取自定义帖子时遇到问题 - Having Issues getting custom posts by Advanced Custom Fields (meta_key and meta_value) 将现有的元值复制到新的元键名称 - WordPress - copy an existing meta_value to a new meta_key name - WordPress 在wordpress上更新新的数据库行以及meta_key和meta_value - Updating new database row along with meta_key and meta_value on wordpress
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM