Show fields on template select

Support General Show fields on template selectResolved

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #45286
    Aaron KesslerAaron Kessler
    Participant

    I have a page template and bound some custom fields to it. I want to use with no other page template. The way I do this is:

    $fields[] = [
      'title' => __('my_title', NAME_SPACE),
      'id' => PREFIX . 'my_id',
      'post_types' => ['page'],
      'include' => [
        'relation'        => 'AND',
        'template'  => ['template-my_template.php'],
      ],
      'context' => 'normal',
      'style' => 'default',
      'fields' => [$my_fields_here]
    

    However, these fields will only show if I save the page with the template selected and reload it. This is very unintuitive. Could this be solved so the fields will show up as soon as the template is selected?

    #45288
    Aaron KesslerAaron Kessler
    Participant

    Oh, I forgot to close the array in this example, but the question remains.

    #45312
    PeterPeter
    Moderator

    Hello Aaron,

    The plugin MB Include Exclude supports including or excluding a field group on page loading. If you want to show/hide a field group based on the page template, please use MB Conditional Logic.

    Please follow the documentation
    https://docs.metabox.io/extensions/meta-box-conditional-logic/#toggle-by-other-elements
    https://docs.metabox.io/extensions/meta-box-include-exclude/

    #45316
    Aaron KesslerAaron Kessler
    Participant

    Ah! I missed that I also can define the visible or hidden key from MB Conditional Logic outside the fields array. Works like expected! Thanks, Peter 😉

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.