Support

Account

Home Forums ACF PRO Query posts by taxonomy field

Solved

Query posts by taxonomy field

  • May I query posts by taxonomy field as one would do for a checkbox field, for example?

    I don’t wish to activated Load or Save terms in the taxonomy field (as I don’t need the extra classes created by post_class function) and was trying to query the posts with meta_query and not tax_query. Possible?

    I haven’t been to get it working.

    My code:

    'meta_query' => array(
                       'relation' => 'OR',
    		   array(
    		      'key' => 'project-fields',
    		      'value' => 'architecture',
    		      'compare' => 'LIKE',
                        ),
    		    array(
    		       'key' => 'project-fields',
    		       'value' => 'research',
    		       'compare' => 'LIKE',
    		    ),
    		 ),

    Thanks.

  • If you are not saving and loading terms then you must use a meta_query. But, ACF stores the term ID of each term selected, not the term name. And you’re like value needs to look something like '"'.$term_id.'"' because ACF stores a serialized array for the selected terms.

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

The topic ‘Query posts by taxonomy field’ is closed to new replies.