Hide a metabox when a parent is selected
Support › MB Conditional Logic › Hide a metabox when a parent is selected
- This topic has 8 replies, 2 voices, and was last updated 9 years, 8 months ago by
Tan Nguyen.
-
AuthorPosts
-
August 9, 2015 at 10:33 PM #1191
Sinusite
ParticipantHi,
I would like to hide some metaboxes (from Meta Box & WordPress) when user select a Parent in the WP dropdown.
Is it possible with Conditional Logic ?
Thank You
August 9, 2015 at 10:36 PM #1192Sinusite
Participantmmmm looks like https://support.metabox.io/topic/if-is-parent/ lol
May be i've chosen the wrong extension :p ?August 9, 2015 at 11:16 PM #1193Sinusite
ParticipantOk... it's workin perfectly for meta-boxes with
'visible' => array('parent_id', '=', ''),
For notice, a comma is missing in the doc
'visible' => array('parent_id', '!=' '')
But how to with the WordPress Metaboxes ? (For example postexcerpt ou a taxonomy_div for a CPT)
Thank You !!August 10, 2015 at 1:02 AM #1194Tan Nguyen
ParticipantHi Sinusite,
Thanks for purchasing Conditional Logic and reporting documentation missing, you rock man 🙂
For postexcerpt or taxonomy_div, you can add filter to rwmb_outside_conditions like so:
add_filter( 'rwmb_outside_conditions', function( $conditions ) { $conditions['postexcerpt'] = array( 'hidden' => array( 'relation' => 'and', 'when' => array( array('post_format', '=', 'aside') ) ) ); return $conditions; } );
P/S: The conditional logic array should be simplified like example below but it's a bug on our extension and you'll get the update on the next 24 hour:
$conditions['postexcerpt'] = array( 'hidden' => array('post_format', 'aside' ) );
Thanks and Best regards
Tan Nguyen
August 11, 2015 at 11:49 PM #1211Tan Nguyen
ParticipantAlso, we've released 1.0.4 and you can use simplified syntax like example above, have a nice day and don't hesitate to tell us if you have any problem 🙂
August 17, 2015 at 7:52 PM #1241Sinusite
ParticipantHi Tan,
Thanks for you quick answer and amazing work.What is the best syntax for multiple fields to hide with the same conditions ?
i.e. :
$conditions['tagsdiv-maitreo'] = array( 'hidden' => array('parent_id', '>', 0 ) );
$conditions['postimagediv'] = array( 'hidden' => array('parent_id', '>', 0 ) );
$conditions['sbg_box'] = array( 'hidden' => array('parent_id', '>', 0 ) );regards.
August 19, 2015 at 11:44 PM #1260Tan Nguyen
ParticipantHi Sinusite,
Great question, I will implement update to get multiple field hide with same condition, currently, this version doesn't support but you can try this snippet for shorter and easier to update. Basically, assign hidden conditions to a variable called
$hidden_condition
and attach that condition to all of your meta boxes:$hidden_condition = ['hidden' => ['parent_id', '>', 0]]; foreach ( ['tagsdiv-maitreo', 'postimagediv', 'sbg_box'] as $metabox ) { $conditions[$metabox] = $hidden_condition; }
Best Regards
August 23, 2015 at 8:31 PM #1281Sinusite
Participantok Thanks !
Last question (before the next one :p ):
What does your "MB Include Exclude" plugin can bring me more ?August 23, 2015 at 10:22 PM #1283Tan Nguyen
ParticipantHi Sinusite,
Thanks again for your question you're welcome to post any question about our Meta Box so please don't hesitate to tell me if you have problems 🙂
As noted in documentation:
"This extension shows/hides meta boxes when page loads or after saving. It does not include Javascript code to toggle meta boxes immediately when conditions changed."The different between Conditional Logic and Include / Exclude basically is:
- Conditional Logic run when field values change immediately while Include/Exclude run conditions on page load.
- Conditional Logic can hide meta box, fields or any DOM element while Include/Exclude only works with meta box.
- Conditional Logic only hide elements, the element still exists while Include/Exclude can totally remove element from the page.
Best regards
Tan Nguyen
-
AuthorPosts
- The topic ‘Hide a metabox when a parent is selected’ is closed to new replies.