我正在使用Redux Framework进行主题开发,但我坚持使用Metabox。我试过这个文档https://docs.reduxframework.com/extensions/metaboxes/,但我没有得到任何结果。
我无法在选定的自定义帖子类型上获取自定义字段。
在extentions-init.php中,我找到了:
//将为Redux实例自动加载扩展目录中的所有扩展。 Redux :: setExtensions($ opt_name,dirname( FILE )。' / extensions /');
// Any custom extension configs should be placed within the configs folder.
if ( file_exists( dirname( __FILE__ ) . '/configs/' ) ) {
$files = glob( dirname( __FILE__ ) . '/configs/*.php' );
if ( ! empty( $files ) ) {
foreach ( $files as $file ) {
include $file;
}
}
}
它清楚地显示自定义元变量将从configs文件夹加载,但它不会加载。
答案 0 :(得分:0)
尝试更类似的内容...请注意,您需要添加add_action(
if ( !function_exists( "master_metaboxes_function" ) ){
function master_metaboxes_function($master_metaboxes) {
if ( file_exists( dirname( __FILE__ ) . '/configs/' ) ) {
$files = glob( dirname( __FILE__ ) . '/configs/*.php' );
if ( ! empty( $files ) ) {foreach ( $files as $file ) {include $file;} }
}
return $master_metaboxes;
}
// note this has to load AFTER the action loads...
add_action('redux/metaboxes/'.$YOUR_OPTION_ID.'/boxes', 'master_metaboxes_function');
}
阅读本文:https://github.com/reduxframework/redux-framework/issues/2605
答案 1 :(得分:0)
正如您在文档中看到的那样,您需要连接到过滤器中以设置元框,因此在您的插件或主题中,添加以下代码:
(不要忘记将{$ redux_opt_name}替换为您唯一的供应商前缀/ opt_name,以防止与其他插件发生共鸣)
if ( !function_exists( "{%redux_opt_name%}_redux_add_metaboxes" ) ):
function {%redux_opt_name%}_redux_add_metaboxes($metaboxes) {
// Declare your sections
$boxSections = array();
$boxSections[] = array(
//'title' => __('General Settings', 'redux-framework-demo'),
//'icon' => 'el-icon-home', // Only used with metabox position normal or advanced
'fields' => array(
array(
'id' => 'sidebar',
//'title' => __( 'Sidebar', 'redux-framework-demo' ),
'desc' => 'Please select the sidebar you would like to display on this page. Note: You must first create the sidebar under Appearance > Widgets.',
'type' => 'select',
'data' => 'sidebars',
),
),
);
// Declare your metaboxes
$metaboxes = array();
$metaboxes[] = array(
'id' => 'sidebar',
'title' => __( 'Sidebar', 'fusion-framework' ),
'post_types' => array( 'page', 'post', 'acme_product' ),
//'page_template' => array('page-test.php'), // Visibility of box based on page template selector
//'post_format' => array('image'), // Visibility of box based on post format
'position' => 'side', // normal, advanced, side
'priority' => 'high', // high, core, default, low - Priorities of placement
'sections' => $boxSections,
);
return $metaboxes;
}
// Change {%redux_opt_name%} to your opt_name
add_filter("redux/metaboxes/{%redux_opt_name%}/boxes", "redux_add_metaboxes");
endif;