Support

Account

Home Forums Front-end Issues Getting terms by custom field

Solving

Getting terms by custom field

    • Nubee

    • June 8, 2016 at 6:09 am

    According to the WP documentation, it appears to be possible to put a meta_query argument to filter the taxonomy terms retrieved by the function get_terms. However, as seen below, I have tried doing it with the same syntax that I was using on my get_posts statement, and it doesn’t work.

    WordPress seems to recognize this as valid, as it changes the results from giving me all terms to an empty array. But I am certain I have several terms where the ACF display_on_page is checked. Am I doing something wrong?

    $locations = get_terms(array(
    	'taxonomy'			=> 'locations',
    	'meta_query'		=> array(
    		'relation'		=> 'AND',
    		array(
    			'key'			=> 'display_on_page',
    			'value'			=> true,
    			'compare'		=> '='
    		)
    	)
    ));
  • ACF has not yet started to use term meta. See this topic for how to create filters that will store acf fields in term meta so they can be used in term queries. https://support.advancedcustomfields.com/forums/topic/how-to-use-wp-term-meta-on-acf-the-easy-way/

    • Nubee

    • June 10, 2016 at 7:00 am

    Thank you very much! I didn’t manage to get it to work properly, so since I don’t have all that many terms, I just fetched them all and put an if statement to control which ones were displayed. But interesting to know that it’s somehow possible.

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.