You can manipulate $post in your block and then use the standard post loop:
$posts = get_posts(array('post_type' => 'YOUR_POSTYPE', 'posts_per_page' => 3 ));
if( $posts ): ?> <?php foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?> <?php setup_postdata($post); ?> // Your code <?php endforeach; ?> <?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?> <?php endif; ?>
If you want to give the user the option to change, let’s say the ammount of posts, then you can set the value of a field as variable in your array:
$number_of_posts = get_field('your field'); $posts = get_posts(array('post_type' => 'YOUR_POSTYPE', 'posts_per_page' => $number_of_posts ));
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!
© 2022 Advanced Custom Fields.