Support

Account

Home Forums ACF PRO Add taxonomy to relationship selection

Helping

Add taxonomy to relationship selection

  • I’m trying to get the ACF Relationship field to list Taxonomies in the selection meta field. I’ve been looking for a solution for a while but just can’t find or figure out the code to do it. I cant use a taxonomy field here because I need the user to be able to select any post, page, etc., and in my specific case, the actual category page, to the selection.

    Im not looking to filter by taxonomies as i know that is already an option.

    The results for instance would then allow me to show a list from the selected posts, pages, etc., and “categories”.

    for example:
    – Hello world! (post)
    – Things to do… (page)
    – New Years Party (event / etc.)
    – Biking (category)

    My guess is to somehow add the categories to the arguments in a function for this specific field.

    something like:

    function add_categories_to_relationship($args, $field, $post_id)
    {
        //1: add categories pages to selection
        $args['???'] = array('category');
    
        return $args;
    }
    add_filter('acf/fields/relationship/query/key=field_60c258b4efd79', 'add_categories_to_relationship', 10, 3);

    any help would be much appreciated.

  • I relationship field cannot be used to select terms in a category.

    A page link field will allow selecting posts and archive pages. This is the closest that you will be able to get using a built in ACF field.

    To allow multiple selections of different type of fields the solution is to use a repeater with multiple sub fields

    1. Link Type – Radio or Select field to select “Post/Page”, “Category”, etc..
    2. Post object fields conditional if “post/page” selected
    3. Category Taxonomy field conditional if “category” is selected
    4. etc…
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.