Support

Account

Home Forums Add-ons Repeater Field Query repeater field rows

Helping

Query repeater field rows

  • Hi,

    Good day to all of you here.

    This is my first time to post a topic.

    I have purchased the ACF Repeater Field plugin and it is working great so far.

    I am currently developing a hospital website and created a doctors’ database using ACF and ACF Repeater Field plugin for the doctor’s schedule.

    My problem is that I have created a custom search form for the doctors’ database and I can’t seem to figure out how to query the repeater fields. Here is my code:

    
    
    				foreach ($days as $day) {
    					if(!empty($day)) {
    					$day = array(
    						 'key' => 'schedule_%_days',
    						 'value' => $day,
    						 'compare' => 'LIKE'
    					);
    					}
    					
    				}
    																
                    $args = array(
                    'post_type'=> 'csmc_doctors',
                    'paged' => $paged,
    				's' => $s,
    				'meta_query' => array(
    						array (
    						 'key' => 'specialization',
    						 'value' => $specialization ,
    						 'compare' => 'LIKE'
    						 ),
    						$day
    					)
                    );
    				
    				
                    $searched_posts = new WP_Query( $args );
                
                    if ($searched_posts->have_posts()) :
    

    My search form has “Days” multiple select where a user can select days from Monday to Sunday. The query works if I change this – schedule_%_days to this -schedule_0_days but it only query the first row of the repeater field because of the value ‘0

    You can check out my form here – http://csmc.losito.com.ph/

    Can anyone help me on this one please?

    Thank you.

  • Hi @jasonlosito

    Querying sub field values requires a little more code:
    http://www.advancedcustomfields.com/resources/how-to/how-to-query-posts-filtered-by-custom-field-values/#example-5

    Please take note of the extra filter needed.

    Thanks
    E

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

The topic ‘Query repeater field rows’ is closed to new replies.