【问题标题】:Every time a post is published, remove all the other published posts每次发布帖子时,删除所有其他已发布的帖子
【发布时间】:2016-11-03 12:28:03
【问题描述】:

问题:由于 RSS 转换为帖子相关问题,我只想在我的博客页面的后端发布一篇博文。我知道我只能显示最后一篇博文,但这不是我想要的。

是否有可以在我每次发布帖子时永久删除/删除已发布的所有其他帖子的功能或插件?

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    我找到了解决方案。我希望它可以帮助有同样问题的人:

    function delete_all_posts_less_the_first() {
        $posts_less_the_first = get_posts( array( 'post_type' => 'post', 'offset' => '1') );
    
        foreach ( $posts_less_the_first as $post_less_the_first ) {
            // Delete all posts less the first.
            wp_delete_post( $post_less_the_first->ID, true); // Set to False if you want to send them to Trash.
        } 
    }
    add_action( 'init', 'delete_all_posts_less_the_first' );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-06
      • 2020-08-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多