【问题标题】:Wordpress add post using front end with different titleWordpress 使用具有不同标题的前端添加帖子
【发布时间】:2015-05-15 06:48:01
【问题描述】:

我想创建系统以将 wordpress 帖子从前端插入到登录用户。但是我已经检查过不同用户多次添加的相同标题帖子。 如果帖子标题已经存在,我如何添加error message

这是我的代码

 $u_id = get_current_user_id(); 
   $my_post = array(
   'post_title'    => 'title',
   'post_content'  => 'this is post content',
   'post_status'   => 'publish',
   'post_author'   => $u_id,
   'post_type'     => 'customer_post',
);

$post_ID = wp_insert_post( $my_post );

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    您可以通过检查某些条件来防止这种情况。你应该试试这个。在此条件下包装您的代码,它将不允许发布具有相同标题的帖子。

    if (!get_page_by_title($title, 'OBJECT', 'post') ){
    
      //your code goes here.
    
     }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-16
      • 1970-01-01
      • 1970-01-01
      • 2018-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多