Follow us on

Codestar Support Forum » WordPress Plugins » Codestar Framework

Cannot control post types' arguments in meta box

  1. Hi Codestar,
    hope you're doing well

    It seems I cannot get metabox to display for just required post types by using the default arguments.
    It's the best through the example.

    Lets say we have a Metabox created and 'post_type' appearance should be regulated through the $set_post_types variable:

    $args =   array( 'public' => true, '_builtin' => false );
    	$set_post_types =   get_post_types( $args );
    
    	CSF::createMetabox($prefix, array(
    		'title'       =>  'my MB',
    		'post_type'   =>  $set_post_types,
    		'context'     =>  'side',
    	) );CopyCopied!

    The problem is that $args do not return the right value for the CSF metabox. In the example above, $args should return all public custom post types.
    You see, if I var_dump the $set_post_types it returns empty.

    ...But if I create a function and hook it into the 'admin_footer' I get the 'product' listed, i.e. the only custom post type I have registered on the site:

    function aaa() {
    
            $args = array(
                'public'   => true,
                '_builtin' => false
            );
    
            $a = get_post_types( $args );
    
            var_dump($a);
        }
    
        add_action('admin_footer', 'aaa');CopyCopied!

    Hope it's clear. Let me know if this can be corrected.

    Posted 1 year ago #

  2. Codestar
    Admin

    Hi,

    Hmm, yes right. Actually it's not an issue. It's a wordpress core action priority thing. Un I am not sure how to explain with poor english. Lets try. I mean:

    The framework starts in action priority 10. If your register_post_type action is register after that priority it will not work as normally. You can see that issue on google.

    //codestar-framework/classes/setup.class.php
    add_action( 'after_setup_theme', array( 'CSF', 'setup' ) ); // default priority 10
    add_action( 'init', array( 'CSF', 'setup' ) ); // default priority 10CopyCopied!

    What is the solution ?

    function slo_init_metabox() {
    
      $args = array( 'public' => true, '_builtin' => false );
      $set_post_types = get_post_types( $args );
    
      var_dump( $set_post_types ); // output test.
    
      CSF::createMetabox($prefix, array(
        'title'     =>  'my MB',
        'post_type' =>  $set_post_types,
        'context'   =>  'side',
      ) );
    
      // options....
    
    }
    add_action( 'after_setup_theme', 'slo_init_metabox', 11 ); // Let's set action priority 11 (It must be big than 10).CopyCopied!

    But still its not guarantee way. Best way is manual give post type name.

    Ok, try it. maybe it works.

    Regards, Codestar

    Posted 1 year ago #