Support

Account

Home Forums ACF PRO Show only categories in the relationship field taxonomy filter Reply To: Show only categories in the relationship field taxonomy filter

  • Thank you mate. It works. If somebody has “Fatal error: [] operator not supported for strings” just add $field[‘taxonomy’] = []; in top of the function like this;

    add_filter('acf/load_field/key=field_60c224887921d', 'load_just_categories_filter', 12, 1);
    function load_just_categories_filter( $field ) {
        $field['taxonomy'] = [];
        $terms = get_terms( array(
            'taxonomy' => 'category',
            'hide_empty' => false,
    		//'hierarchical' => 1,
    		'parent' => 0
        ) );
        if ( !empty($terms) ) {
            foreach( $terms as $term ) {
    			
    			
                $field['taxonomy'][] = 'category:'.$term->slug;
    			
            }
        }
    
        return $field;
    }