Support

Account

Home Forums Add-ons Repeater Field query posts with repeater field

Helping

query posts with repeater field

    • pnoeric

    • October 9, 2013 at 7:43 am

    Hi, I love your plugin and I’ve purchased the repeater field add-on. However, I’m struggling with getting all custom post types that match a field in a repeater field.

    In other words, I have a post type “writers” with two fields, “location” which is a normal field, and “genre” which is a repeater field.

    I need to retrieve all writers with location = Los Angeles and genre = mystery, so I tried this:

    $p2 = get_posts(array(
    	'numberposts' => -1,
    	'post_type' => 'writers',
    	'meta_key' => 'location',
    	'meta_value' => 'los-angeles',
    	'meta_query' => (array('key' => 'genre', value => 'mystery'))
    ));

    …but that didn’t work. Is there a way to use get_posts to query repeater fields?

    • Elliot

    • October 9, 2013 at 10:26 am

    Hi @pnoeric

    the meta_query argument does not work like this.

    To query sub field data, you need to follow this tutorial here:
    http://www.advancedcustomfields.com/resources/tutorials/querying-the-database-for-repeater-sub-field-values/

    Thanks
    E

Viewing 2 posts - 1 through 2 (of 2 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.