我试图让我的自定义字段加载到所有帖子、页面和所有公开的自定义帖子类型上。
但我不知道如何结合它。
这是我设置为在帖子和页面上加载自定义字段的变量
public function vf_add_meta_box( $post_type ) {
if (in_array( $post_type, $this->post_types )) {
add_meta_box(
$this->option_name,
$this->metabox_name,
array( $this, 'meta_box_display' ),
$post_type,
'normal',
'high'
);
}
}
$post_type 在其他函数中定义并插入到 __construct 中,设置如下
$post_types = array('post', 'page' );
并从 wordpress codex 指令中获取所有自定义帖子类型,您可以使用此代码。
$args = array(
'public' => true,
'_builtin' => false
);
$output = 'names'; // names or objects, note names is the default
$operator = 'and'; // 'and' or 'or'
$custom_types = get_post_types( $args, $output, $operator );
foreach ( $custom_types as $post_type ) {
return $post_type ;
}
所以我假设如果我将 $post_type 添加到 $post_types 数组
$post_types = array('post', 'page', $post_type );
它会以自定义帖子类型显示元框,但它不起作用。