Support

Account

Home Forums Add-ons Repeater Field Specific value from repeater > text field

Helping

Specific value from repeater > text field

  • I have a repeater field that I am populating dynamically via acf/save_post. I’m trying to extract two specific values (long/lat) from the repeater in footer.php so I can populate gmaps javascript with location data. The page just seems to churn for 40 seconds then load as normal but with nothing returned from the repeater get_field(). The wp_query works though.

    if ( is_singular( 'schools' ) ) {
    		$postID = get_queried_object_id();
    		
    		$args = array(
    			'post_type' => 'schools',
    			'p' => $postID,
    		);
    
    		$the_query = new WP_Query( $args );
    	
    		if ( $the_query->have_posts() ) {
    
    			while ( $the_query->have_posts() ) {
    
    				$rows = get_field('data_repeater', $postID);
    				var_dump($rows);
    				if($rows)
    				{
    					foreach($rows as $row)
    					{
    						if ( $row['data_name'] === 'lat' ) {
    							$lat_value = $row['data_value'];
    							echo $row['data_value'];
    						}
    						if ( $row['data_name'] === 'long' ) {
    							$long_value = $row['data_value'];
    						}
    					}
    
    				}
    			}
    
    		}
    		wp_reset_postdata();
    	}
  • Fixed – I dont know why this was so hard to achieve

    if ( is_singular( 'schools' ) ) {
    	
    	$postID = get_queried_object_id();
    	$rows = get_field('data_repeater', $postID);
    
    	foreach($rows as $row) {
    		if ( $row['data_name'] === 'lat' ) {
    			$lat_value = $row['data_value'];	
    		}
    		if ( $row['data_name'] === 'long' ) {
    			$long_value = $row['data_value'];	
    		}	
    	}
    }
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.