Limitations of select_tree (field_type)
- This topic has 4 replies, 2 voices, and was last updated 5 years, 11 months ago by
ComSi.
-
AuthorPosts
-
May 28, 2019 at 9:34 PM #14734
ComSi
ParticipantI 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...
- 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? - 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:
May 29, 2019 at 11:09 AM #14743Anh Tran
KeymasterHi ComSi,
- Context: this is set at meta box's level. Did you set for meta box or for the field?
- 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.
May 29, 2019 at 1:41 PM #14748ComSi
ParticipantHi Anh Tran,
-
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? -
Okay. Did not get that from the documentation. Thanks for clearing that up.
May 29, 2019 at 1:59 PM #14750Anh Tran
KeymasterHi 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.
May 29, 2019 at 5:41 PM #14769ComSi
ParticipantI 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! - this overrides the
-
AuthorPosts
- You must be logged in to reply to this topic.