Limitations of select_tree (field_type)

Support General Limitations of select_tree (field_type)Resolved

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #14734
    ComSiComSi
    Participant

    I basically want to replace the default taxonomy metabox (with the checkboxes) for my custom post type. I've added the basic code of the metabox below.

    The problem I'm having is that I love the idea of the "field_type" => "select_tree" setting, but it seems to have some limitations.

    Am I correct that...

    1. this overrides the "context" => "side" and always shows as "context" => "normal" so it ends up below the content textarea instead of to the right side of it?
    2. even though it is documented to have multi select enabled, this is not the case and only one parent / child term can be selected?

    Note that for select_tree, checkbox_list, checkbox_tree, the multiple setting is always set to true.

    Example code:

    $metaboxes[] = array(
        'id'         => 'my_product-info',
        'title'      => __('Product information', 'my-textdomain' ),
        'post_types' => 'my_product',
        'context'    => 'side',
        'fields' => array(
            array(
                'name'       => __('Product Category', 'my-textdomain'),
                'id'         => 'taxonomy',
                'type'       => 'taxonomy',
                'taxonomy'   => 'product_cat',
                'field_type' => 'select_tree',
            ),
        )
    );

    Result:
    No multi-select and not in sidebar

    #14743
    Anh TranAnh Tran
    Keymaster

    Hi ComSi,

    1. Context: this is set at meta box's level. Did you set for meta box or for the field?
    2. Multi-select: the documentation means the value saved for those field types are always multiple (you save both parent and children). But the selection for each level is only one. It's how the tree works.
    #14748
    ComSiComSi
    Participant

    Hi Anh Tran,

    1. Meta box, I think. Not entirely sure what you mean here?
      In my sample code it is set in the root level of the array, not in the nested "fields" key. Did you mean that?
      When I change out the type=taxonomy for type=text for example, it jumps over to the side. Is this because the title/parent/child are too wide for the sidebar maybe?

    2. Okay. Did not get that from the documentation. Thanks for clearing that up.

    #14750
    Anh TranAnh Tran
    Keymaster

    Hi ComSi,

    Have you ever drag and drop the meta boxes? If you have, then WP will save the position/location of them and makes the "context" param not working. The data is saved in the user meta meta-box-order_{screen id}:

    https://i.imgur.com/A7bkxT9.png

    Deleting this user meta from the database will make the context work again.

    Please try that. It's the only reason I think affects the wrong location.

    #14769
    ComSiComSi
    Participant

    I stand corrected, that was the case.

    I was in the understanding that ordering of metaboxes was done in a cookie, not in the usermeta table.
    This solved my problem, thanks!

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