Hide Field On Specific MB Frontend Page Template
Support › MB Frontend Submission › Hide Field On Specific MB Frontend Page TemplateResolved
- This topic has 4 replies, 2 voices, and was last updated 1 year, 2 months ago by
Codog.
-
AuthorPosts
-
January 27, 2024 at 1:04 AM #44408
Codog
ParticipantHi 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.
January 29, 2024 at 8:52 PM #44423Peter
ModeratorHello,
The frontend form doesn't support the field
page_template
as in the admin area. You should create another select field with the IDpage_template
to use the conditional logic in the frontend.January 29, 2024 at 9:37 PM #44425Codog
ParticipantHi 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!
January 30, 2024 at 10:32 PM #44435Peter
ModeratorHello,
You can create a new custom field
select
with the field IDpage_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/January 31, 2024 at 11:42 PM #44447Codog
ParticipantHi Peter,
understood. Thanks! -
AuthorPosts
- You must be logged in to reply to this topic.