Multiple conditions do not apply
Support › MB Conditional Logic › Multiple conditions do not applyResolved
- This topic has 3 replies, 2 voices, and was last updated 1 year, 3 months ago by
Peter.
-
AuthorPosts
-
January 15, 2024 at 4:25 AM #44291
Aaron Kessler
Participantfunction is_event_post_type() { return get_post_type($_GET['post'] ?? null) === PREFIX . 'event'; }
$fields[] = [ 'title' => __('Kontakt', NAME_SPACE), 'id' => PREFIX . 'event_contact_details', 'post_types' => [PREFIX . 'event', 'page'], 'include' => [ 'relation' => 'OR', 'template' => ['template-desc.php'], 'custom' => 'is_event_post_type' ], 'context' => 'normal', 'style' => 'default', 'fields' => [ [ 'id' => PREFIX . 'inherit_event_contact_details_from_desc', 'name' => __('Kontakt überschreiben', NAME_SPACE), 'type' => 'switch', 'style' => 'rounded', 'on_label' => __('Ein', NAME_SPACE), 'off_label' => __('Aus', NAME_SPACE), 'label_description' => __('Überschreibt die Kontakdaten der Termin-Beschreibung', NAME_SPACE), 'hidden' => [ ['page_template', 'template-desc.php'] ] ], [ 'type' => 'custom_html', 'std' => '' . __('Kontakt-Details für Termine. Jeder Termin kann separat überschreiben werden.') . ' ', 'visible' => [ ['page_template', 'template-desc.php'] ] ], [ 'type' => 'heading', 'name' => __('Link-Optionen', NAME_SPACE), 'visible' => [ 'relation' => 'OR', 'when' => [ [PREFIX . 'inherit_event_contact_details_from_desc', true], ['page_template', 'template-desc.php'] ] ] ], [ 'name' => __('Text', NAME_SPACE), 'id' => PREFIX . 'event_link_text', 'type' => 'text', 'desc' => __('Empfohlen, Optional', NAME_SPACE), 'visible' => [ 'relation' => 'OR', 'when' => [ [PREFIX . 'inherit_event_contact_details_from_desc', true], ['page_template', 'template-desc.php'] ] ] ], [ 'name' => __('URL', NAME_SPACE), 'id' => PREFIX . 'event_link_url', 'type' => 'url', 'visible' => [ 'relation' => 'OR', 'when' => [ [PREFIX . 'inherit_event_contact_details_from_desc', true], ['page_template', 'template-desc.php'] ] ] ], [ 'name' => __('Parameter', NAME_SPACE), 'id' => PREFIX . 'event_link_url_params', 'type' => 'checkbox_list', 'inline' => true, 'options' => [ '_blank' => __('URL in einem neuen Fenster/Tab öffnen', NAME_SPACE), 'download' => __('Download', NAME_SPACE), ], 'visible' => [ 'relation' => 'OR', 'when' => [ [PREFIX . 'inherit_event_contact_details_from_desc', true], ['page_template', 'template-desc.php'] ] ] ], [ 'type' => 'divider', 'visible' => [ 'relation' => 'OR', 'when' => [ [PREFIX . 'inherit_event_contact_details_from_desc', true], ['page_template', 'template-desc.php'] ] ] ], [ 'name' => __('E-Mail-Adresse', NAME_SPACE), 'id' => PREFIX . 'event_email', 'type' => 'email', 'visible' => [ 'relation' => 'OR', 'when' => [ [PREFIX . 'inherit_event_contact_details_from_desc', true], ['page_template', 'template-desc.php'] ] ] ], [ 'type' => 'divider', 'visible' => [ 'relation' => 'OR', 'when' => [ [PREFIX . 'inherit_event_contact_details_from_desc', true], ['page_template', 'template-desc.php'] ] ] ], [ 'name' => __('Telefonnummer', NAME_SPACE), 'id' => PREFIX . 'event_phonenumber', 'type' => 'text', 'desc' => __('Die für den Menschen lesbare, formatierte Telefonnummer.', NAME_SPACE), 'visible' => [ 'relation' => 'OR', 'when' => [ [PREFIX . 'inherit_event_contact_details_from_desc', true], ['page_template', 'template-desc.php'] ] ] ], [ 'name' => __('Telefon-Link', NAME_SPACE), 'id' => PREFIX . 'event_phonenumber_raw', 'type' => 'text', 'desc' => __('Die unformatierte Telefonnummer, wie sie auch im Adressbuch eines Telefons verwendet wird.', NAME_SPACE), 'visible' => [ 'relation' => 'OR', 'when' => [ [PREFIX . 'inherit_event_contact_details_from_desc', true], ['page_template', 'template-desc.php'] ] ] ], [ 'name' => __('Barrierefreie Telefonnummer', NAME_SPACE), 'id' => PREFIX . 'event_phonenumber_a11ty', 'type' => 'text', 'desc' => __('Gesprochene Telefonnummer für Benutzer von Screenreadern.', NAME_SPACE), 'visible' => [ 'relation' => 'OR', 'when' => [ [PREFIX . 'inherit_event_contact_details_from_desc', true], ['page_template', 'template-desc.php'] ] ] ], [ 'type' => 'divider', 'visible' => [ 'relation' => 'OR', 'when' => [ [PREFIX . 'inherit_event_contact_details_from_desc', true], ['page_template', 'template-desc.php'] ] ] ], [ 'name' => __('Fax-Nummer', NAME_SPACE), 'id' => PREFIX . 'event_faxnumber', 'type' => 'text', 'desc' => __('Die lesbare, formatierte Faxnummer.', NAME_SPACE), 'visible' => [ 'relation' => 'OR', 'when' => [ [PREFIX . 'inherit_event_contact_details_from_desc', true], ['page_template', 'template-desc.php'] ] ] ], [ 'name' => __('Barrierefreie Faxnummer', NAME_SPACE), 'id' => PREFIX . 'event_faxnumber_a11ty', 'type' => 'text', 'desc' => __('Gesprochene Faxnummer für Benutzer von Screenreadern.', NAME_SPACE), 'visible' => [ 'relation' => 'OR', 'when' => [ [PREFIX . 'inherit_event_contact_details_from_desc', true], ['page_template', 'template-desc.php'] ] ] ], ], ];
i would expect the fields like
PREFIX . event_link_text
to show up in pages wehre template-desc.php is applied and on thePREFIX . 'event'
post type. whenPREFIX . 'inherit_event_contact_details_from_desc'
is toggled (true). But something must be wrong with'visible' => [ 'relation' => 'OR', 'when' => [ [PREFIX . 'inherit_event_contact_details_from_desc', true], ['page_template', 'template-desc.php'] ]
i can get only one of the conditonals to work. As far as i can tell i did nothing wrong. Please fix this bug or prove me wrong.
January 15, 2024 at 10:26 PM #44299Peter
ModeratorHello,
i can get only one of the conditionals to work
, it is obvious based on your condition.The field
inherit_event_contact_details_from_desc
is hidden whenpage_template
istemplate-desc.php
:[ 'id' => PREFIX . 'inherit_event_contact_details_from_desc', 'name' => __('Kontakt überschreiben', NAME_SPACE), 'type' => 'switch', 'style' => 'rounded', 'on_label' => __('Ein', NAME_SPACE), 'off_label' => __('Aus', NAME_SPACE), 'label_description' => __('Überschreibt die Kontakdaten der Termin-Beschreibung', NAME_SPACE), 'hidden' => [ ['page_template', 'template-desc.php'] ] ]
If you set the condition of the field
event_link_text
displayed when the fieldinherit_event_contact_details_from_desc
istrue
andpage_template
istemplate-desc.php
, one condition will not work.
Because ifpage_template
istemplate-desc.php
, the fieldinherit_event_contact_details_from_desc
is hidden and you cannot switch on/off the field.Also, please notice that the nested conditional logic is not working correctly. That means if the field
event_link_text
is shown/hidden based on the fieldinherit_event_contact_details_from_desc
value and the fieldinherit_event_contact_details_from_desc
is shown/hidden based on another condition, the condition of the fieldevent_link_text
will not work correctly. Refer to this topic https://support.metabox.io/topic/or-logic-not-working/January 15, 2024 at 11:48 PM #44303Aaron Kessler
ParticipantThanks. I defined separate meta boxes for the custom post type and the page template for now. If https://support.metabox.io/topic/or-logic-not-working/ is still not supported after 3,5 years, should it not be mentioned in https://docs.metabox.io/extensions/meta-box-conditional-logic/ ?
January 16, 2024 at 8:55 PM #44308Peter
ModeratorHello,
Regarding the nested condition, the development team is still working on this issue and it looks more complicated. Hopefully, it will be fixed soon.
Thank you.
-
AuthorPosts
- You must be logged in to reply to this topic.