Home Forums Feature Requests acf / fields / taxonomy / query: Filter by selecting value of a taxonomy


acf / fields / taxonomy / query: Filter by selecting value of a taxonomy

  • Hello you,
    I am currently trying to use a filter to output taxonomy with a selection filter instead of using an ID, and after many attempts I am stuck (beginner PHP knowledge).

    1. ACF select field added in custom taxonomy (Name: Widgets) to categorize individual taxonomies. (In code: Comment No. 1)
    Taxonomy 1 = Selection value field: News
    Taxonomy 2 = Selection value field: Events
    Taxonomy 3 = Selection value field: News

    2. In the custom post, I select a category (e.g. events) using the ACF taxonomy field. Then another taxonomy field is shown to me (taxonomy from point 1).
    Since the selected category is “Events”, all taxonomies with the value “Events” should now be given to me.

    I know it is possible to do this manually using Taxonime-ID’s (in code: Comment No. 2), but I would like to simplify it e.g. For example, if a new taxonomy is added in “widgets”, include it in the select field and not always have to add it manually in the code in the future.

    Original ACF code:

    function qc_widgetlist ( $args, $field, $post_id ) {
    	$args['include'] = '43, 45,'; //Only display custom taxonomy with these taxonomy IDs
        return $args;   
    add_filter('acf/fields/taxonomy/query/name=widgetcat_events', 'qc_widgetlist', 10, 3);

    My attempt:

    function qc_widgetlist ( $args, $field, $post_id ) {
        if( $field['name'] == 'widgetcat' ) { //Select-Field
    		$args['include'] = 'events'; //Select-Field-Value from Events
        return $args;   
    add_filter('acf/fields/taxonomy/query/name=widgetcat_events', 'qc_widgetlist', 10, 3);

    It would make it a lot easier for me if someone of you could help me with this problem.

    Thank you very much,

    (Info: Entry created by translator).

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.