Conditional logic does not work based on a taxonomy field

Support MB Conditional Logic Conditional logic does not work based on a taxonomy fieldResolved

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #12367
    Hansjakob FehrHansjakob Fehr
    Participant

    Hello.
    I'd like to show/hide a meta box with conditional logic, based on a taxonomy_advanced-field, but it does not work.
    I dried it with a radio button and there it works fine.
    Thank you for your help.
    Best regards
    Jacob

    #12370
    Hansjakob FehrHansjakob Fehr
    Participant

    It works also when i use post_category … but just when i use it in the category meta box.
    Post_category with taxonomy field does not work.

    I dried it different ways:
    //array( 'slug:post_category', 'in', array( 'buch' ) ),
    //array( 'slug:tax_input[medium]', 'in', array( 'buch' )),
    //array( 'slug:tax_input[medium]', '=', 'buch' ),
    //array( 'medium', 'in', array( 'buch' )),
    //array ('medium','=','buch', ),

    What do i wrong?
    Thanks again.
    Jacob

    #12389
    Anh TranAnh Tran
    Keymaster

    Hi Jacob,

    I think array( 'medium', 'in', array( 'buch' )) should work for taxonomy_advanced. Would you mind posting the code of meta box here for testing?

    #12392
    Hansjakob FehrHansjakob Fehr
    Participant

    Hi Anh
    Thank you for your helping hand.
    Here comes my code.
    Thank you.
    best regards
    Jacob

    https://ghostbin.com/paste/wnzp9

    #13406
    Hansjakob FehrHansjakob Fehr
    Participant

    Hi Anh
    It has been some time since my question. Now I want to finally solve the problem. Unfortunately, the conditional logic does not work with taxonomy_advanced. With post_category it works fine. Could you look at my problem again?
    Thanks and best regards
    Jacob

    #13407
    Hansjakob FehrHansjakob Fehr
    Participant

    … and here is the code:

    function Buch( $meta_boxes ) {
        $meta_boxes[] = array(
            'title' => 'Buch',
            'context' => 'advanced',
            'autosave' => true,
            'visible' => array (
                'when' => array (
                array('slug:tax_input[medium]', '=', 'buch' ),
              ),
            'fields' => array(
                array(
                'id' => 'format',
                'type' => 'text',
                'name' =>  'Format',
                ),
            ),
        );
        return $meta_boxes;
    }
    add_filter( 'rwmb_meta_boxes', 'Buch' );
    
    function Projekt( $meta_boxes ) {
        $meta_boxes[] = array(
            'title' => 'Projekt',
            'context' => 'advanced',
            'autosave' => false,
            'fields' => array(
                array(
                'name' => 'Datum',
                'id' => 'datumProjekt',
                'type' => 'date',
                'columns' => 3,
                ),
                array(
                'name' => 'Medium',
                'id' => 'medium',
                'type' => 'taxonomy_advanced',
                'taxonomy' => 'medium',
                'field_type' => 'select_advanced',
                'columns' => 3,
                'hidden' => array( 'levelSerie', '=', 'subS' ),
                ),
            ),
        ); 
    }
        return $meta_boxes;
    }
    add_filter( 'rwmb_meta_boxes', 'Projekt' );
    #13430
    Anh TranAnh Tran
    Keymaster

    Hi Hansjakob Fehr,

    I misunderstood in the previous replies. My replies above worked for WordPress's taxonomy box.

    For your situation, as the conditional field is just a normal Meta Box field, you don't need complex conditions. Instead, you can just write:

    'visible' => array (
        'when' => array (
            array('medium', '=', 2 ),
        ),
    ),

    Where 2 is the ID of the term buch. The taxonomy advanced field uses term IDs, so we have to use them instead of slugs.

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