Custom post types without templates and pages with templates

Support MB Show Hide Custom post types without templates and pages with templates

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #6548
    levelbrandlevelbrand
    Participant

    I have a meta box I need to show up for both a custom post type (that doesn't use page templates) and a few pages (that do use page templates). Since the custom post type doesn't use page templates, it seems to be hiding the meta box for those. How do I configure this to work? Here is my current configuration:

    
    $meta_boxes[] = array(
      'id' => '...',
      'title' => '...',
      'post_types' => array( 'page', 'solution' ),
      'show' => array(
        'template' => array(
          'page-templates/about-page.php',
          'page-templates/outcomes-page.php',
        ),
      ),
      'fields' => array(
        ...
      )
    );
    

    Thanks!

    #6561
    Anh TranAnh Tran
    Keymaster

    Hi, I think you need to separate them into 2 meta boxes. In this situation, the logic is applied to only 1 CPT. It's better to separate them.

    You can put fields into a parameter to save your code, like this:

    $fields = array(); // Your fields for both meta boxes here
    $meta_boxes[] = array(
        'id' => 'first-id',
        'post_types' => 'page',
        'show' => array(),
        'fields' => $fields,
    );
    $meta_boxes[] = array(
        'id' => 'another-id',
        'post_types' => 'solution',
        'fields' => $fields,
    );
    #6590
    levelbrandlevelbrand
    Participant

    Thanks! This solutions makes sense.

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘Custom post types without templates and pages with templates’ is closed to new replies.