G
G
ggok2020-04-16 00:44:39
WordPress
ggok, 2020-04-16 00:44:39

How to hide taxonomies when adding a post?

Hello.
There is a post type + 3 taxonomies for it, each taxonomy is a city and categories for it
post type - company
taxonomy - moscow
taxonomy - spb
taxonomy - omsk

When you add a post, 3 taxonomies are displayed and you need to select categories from them, it turns out not convenient and not aesthetically pleasing.
I want to do this: when adding a post, a city (taxonomy) is selected, then a list of categories is displayed.
There is a pro version of acf, I tried to play with it, but it doesn’t work, I don’t even know which direction to look. Give advice or point me in the right direction :) thanks

5e977ec4c15f7038532497.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Vorotnev, 2020-04-16
@ggok

You will be told conditional rules.
Create one field with a choice of taxonomies (cities). It can be a select, radio, checkbox type field - depends on whether you need to select one or more cities. Add all your cities/taxonomies to the values ​​of this field. You can do this manually, or you can programmatically fill in from existing taxonomies.
Further, under each taxonomy (city), create your own field of the Taxonomy type, in which the terms will be selected. Check the Create Terms, Save Terms and Load Terms checkboxes in this field, and also turn on Conditional Logic - that's where the magic is. Now in conditional set up the condition. This is how it looks:
5e9820dca3b3f788190769.jpeg
And this is how it looks on the post editing page - by default, the city is not selected:
5e9820f420767468763297.jpeg
And if you chose a city, it showed a field for choosing a category in this city:
5e9821140e5ab394583256.jpeg
Here is the export of this test group of fields, import it into ACF and tinker with it:

[
    {
        "key": "group_5e981df6cbdcc",
        "title": "Taxonomies",
        "fields": [
            {
                "key": "field_5e981e4bb1454",
                "label": "City",
                "name": "taxonomy",
                "type": "checkbox",
                "choices": {
                    "spb": "SPB",
                    "msk": "Moscow",
                    "omsk": "Omsk"
                },
                "layout": "vertical",
                "return_format": "value",
            },
            {
                "key": "field_5e981e18b1453",
                "label": "MSK",
                "name": "term",
                "type": "taxonomy",
                "conditional_logic": [
                    [
                        {
                            "field": "field_5e981e4bb1454",
                            "operator": "==",
                            "value": "msk"
                        }
                    ]
                ],
                "taxonomy": "post_tag",
                "field_type": "checkbox",
                "add_term": 1,
                "save_terms": 1,
                "load_terms": 1,
                "return_format": "id",
                "multiple": 0,
                "allow_null": 0
            }
        ],
        "location": [
            [
                {
                    "param": "post_type",
                    "operator": "==",
                    "value": "post"
                }
            ]
        ],
        "menu_order": 0,
        "position": "side",
        "style": "default",
        "label_placement": "top",
        "instruction_placement": "label",
        "active": true,
    }
]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question