wordpress发布文章可以选择用户或者作者

有时候在我们做WordPress主题开发的时候,会需要在发布文章的时候选择作者或者用户,然后把文章和指定用户做好关联,方便我们前台的一些数据展示,但是WordPress默认的发布文章的界面是没有这个功能的,那么我们如何才能实现这以功能呢?其实也很简单,只需要我们把以下代码放到您的functions.php文件中就行了。

  1. add_action( 'admin_menu', 'remove_author_metabox' );  
  2. add_action( 'post_submitbox_misc_actions', 'move_author_to_publish_metabox' );  
  3. function remove_author_metabox() {  
  4.     remove_meta_box( 'authordiv', 'post', 'normal' );  
  5. }  
  6. function move_author_to_publish_metabox() {  
  7.     global $post_ID;  
  8.     $post = get_post( $post_ID );  
  9.     echo '<div id="author" class="misc-pub-section" style="border-top-style:solid; border-top-width:1px; border-top-color:#EEEEEE; border-bottom-width:0px;">作者: ';  
  10.     post_author_meta_box( $post );  
  11.     echo '</div>';  
  12. }  

原文地址:https://www.wp-diary.com/1953.html

未经允许不得转载:玫瑰屋工作室 » wordpress发布文章可以选择用户或者作者