Conditional Logic with Childe Taxonomy

Support MB Conditional Logic Conditional Logic with Childe Taxonomy

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #42326
    KaraKara
    Participant

    Hi there -

    I have a taxonomy that includes parent/child options.
    I need to set up a condition to show a group based on whether the child is selected.

    I can get the show/hide functionality to work when there are no child options related, but cannot it doesn't work when there are.

    Here's a screen recording: https://www.awesomescreenshot.com/video/18566416?key=4e280436262f2fad7cf8c44c23021413
    The start was meant to show the taxonomy IDs but they seemed to get cut off.
    Here they are:
    Taxonomy: Test options

    <ul>
    	<li>On = 106
    </ul>
    	<li>Options = 108
    </li>
    	     <li>On = 109
    </li>
    <ul>

    Here's the PHP Code:

    <div><?php
    add_filter( 'rwmb_meta_boxes', 'your_prefix_function_name' );
    
    function your_prefix_function_name( $meta_boxes ) {
        $prefix = '';
    
        $meta_boxes[] = [
            'id'         => 259,
            'post_types' => ['member-content'],
            'fields'     => [
                [
                    'name'       => __( 'Taxonomy', 'your-text-domain' ),
                    'id'         => $prefix . 'taxonomy_ouqiyz69ayl',
                    'type'       => 'taxonomy_advanced',
                    'taxonomy'   => ['test-option'],
                    'field_type' => 'select_tree',
                ],
                [
                    'name'    => __( 'Show when taxonomy is On (no child)', 'your-text-domain' ),
                    'id'      => $prefix . 'show_when_parent_taxonomy_is_on',
                    'type'    => 'text',
                    'visible' => [
                        'when'     => [['taxonomy_ouqiyz69ayl', 'in', 106]],
                        'relation' => 'and',
                    ],
                ],
                [
                    'name'    => __( 'Show when child taxonomy is On', 'your-text-domain' ),
                    'id'      => $prefix . 'child_taxonomy_on',
                    'type'    => 'text',
                    'visible' => [
                        'when'     => [['taxonomy_ouqiyz69ayl', 'in', ['109']]],
                        'relation' => 'and',
                    ],
                ],
            ],
        ];
    
        return $meta_boxes;
    }</div>

    Any ideas?
    Thanks!

    #42332
    PeterPeter
    Moderator

    Hello,

    I see the conditional logic does not work with the field type select_tree. Please use other field types like select_advanced, checkbox_tree, to make it works.

    #42335
    KaraKara
    Participant

    Thanks for getting back to me, Peter.

    Is it possible to request this feature is added to the roadmap?

    We have a *lot* of options for taxonomies and the select_tree option is the best for user experience here. We need to be able to choose a single parent, and a single child taxonomy option (from the selected parent) for each post.

    The conditional logic then calls up the custom fields related to that child taxonomy.

    I understand the checkbox_tree could technically work here, but the goal is to make this as user-friendly as possible for my client, as well. The select_tree puts in the guard rails needed to maintain the integrity of the sitemap.

    I'm very open to other solutions - this turned into an unexpected roadblock.

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