1

I am using Redux Framework for theme development but I stuck on Metabox. I tried this doc https://docs.reduxframework.com/extensions/metaboxes/ but I didn't get any result.

I am unable to get the custom field on selected custom post type.

In extentions-init.php, I found:

// All extensions placed within the extensions directory will be auto-loaded for your Redux instance.
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;
        }
    }
}

It's clearly shows the custom metabox will be load from configs folder but it doesn't load.

2 Answers 2

1

Try something more like this... note that you need to 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'); 
}

Read this: https://github.com/reduxframework/redux-framework/issues/2605

Sign up to request clarification or add additional context in comments.

Comments

0

As you can see in the documentation you need to hook into a filter to set your metaboxes, so in your plugin or theme, add this code :

(don't forget to replace {$redux_opt_name} with your unique vendor prefix/opt_name to prevent colissions with other plugins)

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;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.