【问题标题】:Wordpress: How to delete post with specific content automaticallyWordpress:如何自动删除具有特定内容的帖子
【发布时间】:2013-03-12 18:03:34
【问题描述】:

我想使用 WP-Crontrol 自动删除包含特定内容的 Wordpress 帖子(或者可能是我还不知道的更好的解决方案)。 我添加了以下 cron 作业,但它没有做任何事情:

global $wpdb;
$result = $wpdb->get_results( "SELECT ID FROM wp_posts WHERE post_content LIKE 'Content which should result in a deletion of this post'" );
  if ($result){
    foreach($result as $pageThing){
      wp_delete_post($pageThing);
    }
  }

我怎样才能让它工作? 谢谢

http://wordpress.org/extend/plugins/wp-crontrol/

【问题讨论】:

    标签: php cron wordpress


    【解决方案1】:

    您需要在 cron 脚本的顶部 require_once('absolute-path/wp-load.php') 然后运行您的脚本。您现在拥有的应该可以工作。

    【讨论】:

    • 遗憾的是,这无济于事:$parse_uri = explode('wp-content', $_SERVER['SCRIPT_FILENAME']); require_once($parse_uri[0].'wp-load.php');全球 $wpdb; $result = $wpdb->get_results("SELECT ID FROM wp_posts WHERE post_content LIKE '内容应该导致该帖子被删除'"); if ($result){ foreach($result as $pageThing){ wp_delete_post($pageThing); } }
    • 为什么没有帮助?当您从 bash 或 Web 运行 PHP 脚本时会发生什么?
    猜你喜欢
    • 2020-04-15
    • 2017-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-04
    • 2020-06-11
    • 2017-06-02
    相关资源
    最近更新 更多