Support

Account

Home Forums Add-ons Flexible Content Field Repeaterfields inside flexible content field

Helping

Repeaterfields inside flexible content field

  • Hi,

    I’m trying to display some repeater fields which are located inside a flexible content field. It’s set up outside the regular loop. This is my code so far:

    <?php 
    function get_ajax_content( $page ){
    	
    	$args = array(
    		'page_id' => $page
    	);
    	
    	$the_query = new WP_Query( $args );
    	
    	$result = array('html' => '');
    	
    	while ( $the_query->have_posts() ) : 	$the_query->the_post();
    	
    		if( have_rows( 'content') ):
    			
    			
    			while ( have_rows('content') ) : $row = the_row();  		
    				
    				if( have_rows('list_item') ): while ( have_rows('list_item') ) : the_row(); 
    				 $result['html'] = '<p>Hello!</p>';
    				  // do something 
    				endwhile; endif;
    				
    			endwhile;
    		
    		
    		endif;
    		
    		
    		
    	endwhile;
    	
    	return $result;
    }?>

    It seems to be able to locate the flexible content field, but not the repeater field πŸ™ Any help would be greatly appriciated

  • I know this is an old question, but an answer may still help someone.

    When doing a query inside a function, if you want to use things like the_post(); and $post->ID you must first declare the global $post variable before using them and you must reset the post data after your loop is done running.

    
    function get_ajax_content( $page ){
      global $post;
      // your query and loop here
      wp_reset_post_data();
      return $result;
    }
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Repeaterfields inside flexible content field’ is closed to new replies.