【问题标题】:Update WordPress post with cron job使用 cron 作业更新 WordPress 帖子
【发布时间】:2018-04-13 21:30:36
【问题描述】:

我试图在 X 天后删除 WordPress 帖子。 我正在使用这段代码。

$daystogo = 30;
$sql =
    "UPDATE {$wpdb->posts}
    SET post_status = 'trash'
    WHERE (post_type = 'post' AND post_status = 'publish')
    AND DATEDIFF(NOW(), post_date) > %d";
$wpdb->query($wpdb->prepare( $sql, $daystogo ));

但我想排除一些关于元键的帖子。 就像我不想删除 FEATURD POST VALUE IS 1 的帖子

  'meta_query' => array(
        array(
            'key' => 'featured_post',
                'value' => '1',
                'compare' => '=='
                )
            ),

有什么方法可以在查询中添加这个条件?? 谢谢

【问题讨论】:

    标签: php sql wordpress cron


    【解决方案1】:

    这是给你的mysql代码,你可以使用MySQL的“IN()”函数:

    $sql =
        "UPDATE {$wpdb->posts}
        SET post_status = 'trash'
        WHERE (post_type = 'post' AND post_status = 'publish') 
        AND ID not in (select post_id from {$wpdb->postmeta} where 
        meta_key='featured_post' and meta_value='1' )
        AND DATEDIFF(NOW(), post_date) > %d";
    

    【讨论】:

    • 谢谢我的朋友 :)
    猜你喜欢
    • 1970-01-01
    • 2021-10-29
    • 2014-11-30
    • 2019-02-22
    • 2015-01-30
    • 2014-08-31
    • 2020-06-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多