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');
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.