Hide Field On Specific MB Frontend Page Template

Support MB Frontend Submission Hide Field On Specific MB Frontend Page TemplateResolved

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #44408
    CodogCodog
    Participant

    Hi there,
    I have a MB Frontend submission form. I use a template (EG: template_x.php) where users submit a post for the first time, where the post is set to a 'pending' status when submitted. I have a second template (EG: template_y.php) where users can edit their post once it has been reviewed by an admin and set to a 'publish' status. Both templates use the same frontend form and custom fields. All works fine.

    The problem
    ============

    I have a field that I only wish to show in 'template_x.php' and not in 'template_y.php'. So I turned on the conditional logic extension in AIO and in my field added the following:

    [
    	'name'     => __( 'Choose option', 'text-domain' ),
    	'id'       => $prefix . 'choices',
    	'type'     => 'radio',
    	'desc'        => __( 'Field description', 'text-domain' ),
    	'options'  => [
    		'firstchoice'   => __( 'Choice One', 'text-domain' ),
    		'secondchoice' => __( 'Choice Two', 'text-domain' ),
    	],
    	'required' => true,
    	'inline'   => false,
    	'hidden' => [ 'page_template', 'template_y.php' ], // Hide field in this template
    ],

    Unfortunately, this does not seem to hide this field within 'template_y.php' as expected. Instead the field is still shown in both templates. I have also tried the inverse but the result is the same?

    I have also tried putting in the full path to the template. EG:

    'hidden' => [ 'page_template', '../path-to-template/template_y.php' ],

    But makes no difference?

    I am not seeing any PHP or Console errors?

    Am I misunderstanding how this feature should work?

    I look forward to your response.

    #44423
    PeterPeter
    Moderator

    Hello,

    The frontend form doesn't support the field page_template as in the admin area. You should create another select field with the ID page_template to use the conditional logic in the frontend.

    #44425
    CodogCodog
    Participant

    Hi Peter,
    not sure what you mean by ..."create another select field with the ID page_template to use the conditional logic in the frontend"....

    Can you elaborate or show me an example of how to achieve my goal with your described method?

    Thanks in advance!

    #44435
    PeterPeter
    Moderator

    Hello,

    You can create a new custom field select with the field ID page_template to use the conditional logic. Then after saving the post, you can use the code to update the page template.
    Please follow this article https://tommcfarlin.com/programmatically-set-a-wordpress-template/
    and documentation https://docs.metabox.io/actions/rwmb-after-save-field/

    #44447
    CodogCodog
    Participant

    Hi Peter,
    understood. Thanks!

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