Support

Account

Home Forums General Issues Multiple Post Object in Group Reply To: Multiple Post Object in Group

  • This code seems to work but output sample-page and few blank HTML. It seems like i am missing something simple.

    
    // Shortcode  [post_grid]
    if ( ! function_exists('post_grid_shortcode') ) {
        function post_grid_shortcode( $atts ){
    
    	global $post;
    
    if( have_rows('post_grid') ):
      while( have_rows('post_grid') ): the_row(); 
    
    // 2
    $featured_posts = get_sub_field('ranking');
    if( $featured_posts ): 
        
    	//
    	foreach( $featured_posts as $post ): 
    	setup_postdata($post);
    
    	//foreach( $featured_posts as $featured_post ): 
    		$permalink = get_permalink( $featured_post->ID );
            $title = get_the_title( $featured_post->ID );
    
    		?>
    		<a href="<?php echo esc_url( $permalink ); ?>" class="10"><?php echo esc_html( $title ); ?></a>
    		<a href="<?php the_permalink(); ?>" class="11"><?php the_title(); ?></a>
        <?php 
        
    	//endforeach;
    
    endforeach;
    wp_reset_postdata();
    	//
    
     endif;
    
    //2
    endwhile;
    endif;
    
    	}
    	
    }
    add_shortcode('post_grid', 'post_grid_shortcode');