对自定义帖子类型的多编辑支持:
有一种方法可以将多个内容节添加到自定义帖子类型编辑屏幕:
演示插件:
您可以使用以下演示插件作为页面的扩展。使用MultiEdit插件,添加对自定义帖子类型的支持:
<?php
/**
* Plugin Name: MultiEdit support for custom post type
* Description: You must have the Page.ly MultiEdit plugin installed.
* Plugin URI: http://wordpress.stackexchange.com/a/143688/26350
* Author: birgire
* Version: 0.0.1
*/
add_action( \'load-post.php\', \'wpse_143674_init\' );
function wpse_143674_init()
{
//--------------------------------
// EDIT this setup to your needs:
//
$args = array(
\'post\' => array( \'Bottom\', \'Center\', \'Top\' ),
\'news\' => array( \'Left\', \'Right\' ),
);
$m = new WPSE_Multi_Edit_CPT( $args );
$m->init();
}
/**
* Class WPSE_Multi_Edit_CPT
*/
class WPSE_Multi_Edit_CPT
{
protected $args = array();
protected $screen_id = \'\';
public function __construct( $args = array() )
{
$this->args = $args;
}
public function init()
{
$this->screen_id = get_current_screen()->id;
if( function_exists( \'multieditAdminHeader\' ) // check if Multi Edit plugin is installed
&& 0 < count( $this->args ) // check if input arguments exists
&& \'page\' !== $this->screen_id // dont\' want \'page\' post type
&& in_array( $this->screen_id, array_keys( $this->args ), TRUE ) // match input arguments
)
add_action ( \'admin_footer\', array( $this, \'do_multi_meta\'), 1 );
}
public function do_multi_meta()
{
global $post;
// Multi content sections for the current post type:
$multi = ( isset( $this->args[$this->screen_id] ) ) ? $this->args[$this->screen_id] : array();
// Load scripts:
multieditAdminHeader();
// We have multiedit zones, load js and css load
add_action ( \'edit_page_form\', \'multieditAdminEditor\', 1 );
add_action ( \'edit_form_advanced\', \'multieditAdminEditor\', 1 );
// Current post meta:
$meta = has_meta( $post->ID );
// What tabs to display:
$present = array();
foreach( $meta as $k => $v )
{
if( in_array( $region = str_ireplace( \'multiedit_\',\'\', $v[\'meta_key\'] ), $multi, TRUE ) ):
$present[$region] = TRUE;
else:
unset( $meta[$k] );
endif;
}
//Draw HTML:
drawMultieditHTML( $meta, $present );
// If custom field is not declared yet, create one with update_post_meta
foreach( $multi as $region )
{
if( ! isset( $present[$region] ) )
update_post_meta( $post->ID, \'multiedit_\' . $region, \'\' );
}
}
} // end class
将上述代码添加到文件中
/wp-content/plugins/multiedit-cpt/multiedit-cpt.php
并激活它。
您只需根据需要编辑设置:
$args = array(
\'post\' => array( \'Bottom\', \'Center\', \'Top\' ),
\'news\' => array( \'Left\', \'Right\' ),
);
希望这有帮助。