Support

Account

Home Forums Add-ons Flexible Content Field How to do a connection operation with all the fields?

Unread

How to do a connection operation with all the fields?

  • Hello everyone and thank you very much for the help

    I have a code that brings me all the fields from all the posts in the following way:

    
    	// Get arguments for all posts
    $args = array( 
    	'posts_per_page' => -1,
    );
    
    // Create the array for all posts
    $all_posts = array();
    
    // Set up the query
    $the_query = new WP_Query( $args );
    
    // Setup the loop
    if ( $the_query->have_posts() ):
    
    	while ( $the_query->have_posts() ): $the_query->the_post();
    
    		// Get all fields
    		$fields = get_field('number');
    
    		// Push each $fields array into the $all_posts array
    		array_push($all_posts, $fields);
    
    	endwhile;
    
    	// Restore original Post Data
    	wp_reset_postdata();
    
    	// Print the result here and do what you choose
    	print_r($all_posts);
    
    endif;
    

    Now what I’m trying to do is to connect all the “number” fields. I found that if I have 3 in post 1 and 3 in the second post, then the result will be 4 connecting all the posts according to this field. Does anyone have an idea?

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.