Support

Account

Home Forums Add-ons Repeater Field Query posts by nested sub custom field values

Solved

Query posts by nested sub custom field values

  • Hi there,

    I’m creating a page to filter custom post type results querying posts by custom fields. To do this I followed this guide: https://www.advancedcustomfields.com/resources/query-posts-custom-fields/

    Specifically, I focused on step #4 (Sub custom field values) of the guide, dynamically retrieving parameters using $_GET and It works perfectly but I need to reach a set of subfields in a nested repeater inside the first repeater, but I can’t understand how.

    In the attached screenshot of the JSON, I highlighted in red the repeater field, and relative subfield values that I’m not able to reach in order to use them in the query to filter the results.

    json

    If anyone is able to help me with this I really appreciate it, now I’ve been on this for three days and I still can’t figure out how to do it.

    Thanks in advance!

  • After talking with the ACF support, I can confirm that the following method worked for me:

    When filtering based on nested repeater subfields, you will need to add the replace $ with % code twice

    // filter 
    function my_posts_where( $where ) { 	 	
    
    $where = str_replace("meta_key = 'locations_$", "meta_key LIKE 'locations_%", $where); 	
    
    $where = str_replace("meta_key = 'city_$", "meta_key LIKE 'city_%", $where); 	
    
    return $where; 
    
    }
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.