Home Forums Backend Issues (wp-admin) Limit post-object field to only top-level taxonomy terms?


Limit post-object field to only top-level taxonomy terms?

  • Is it possible to limit the post-object field to only allow posts from top-level taxonomy terms?
    I have a multi-level taxonomy and I only want the user to be able to choose posts assigned to the top level of the taxonomy. Right now I can choose to filter by the top-level terms, but it automatically shows any posts assigned to those terms’ children.
    Can I either stop that from happening or list the exact posts they can choose from?


  • I modified the post_object.php field to accomplish this. It’s attached.

    There is a method called acf_get_taxonomy_terms() that is getting all the terms for the options. I pulled that function from the api-helpers.php file and updated it slightly to include the ‘parent’ => 0 parameter in its get_terms() call. I put the new method in my updated file and called it instead of acf_get_taxonomy_terms() and it seems to work as expected. Adding it as a new field option is the easiest way. Look at Creating a New Field Type to see how to do that. For this though, you can just add the attached file to your system (I just included it at the bottom of my functions.php file) and it should become available.

  • The download doesn’t work for some reason. Just keeps reloading the page.

    Anyway, your approach seems promising. Unfortunately, I realized I also need the same field to be CONDITIONAL. Meaning I need other fields to be able to be conditional based on its value. Alas, I guess you can’t do that with taxonomy or post fields. 🙁

    Oh, the power a dynamic conditional field would give us! And especially if we could dial in the taxonomy level we wanted!


Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Limit post-object field to only top-level taxonomy terms?’ is closed to new replies.