Hi.
I have a code that works ok, but i want to limited it to 4 rows only and in random order:
$parentpost_id = wp_get_post_parent_id( $post_ID );
if( have_rows('list_products', $parentpost_id) ):
while ( have_rows('list_products', $parentpost_id) ) : the_row();
$product = get_sub_field('product', false, false);
$photo = get_sub_field('obrazek');
echo '<a class="product" href="' . get_the_permalink($product) . '"><img src="' . $photo['sizes']['thumbnail'] . '"><h4>' . get_the_title($product) . '</h4></a>';
endwhile;
endif;
photo = image object
product = post object
I was trying foreach loop etc buy with ‘wp_get_post_parent_id’ nothing works. Can you help me?
I’m not sure what you’re having a problem with, getting the post parent or showing the random list. So let’s start with the first one.
Where is the value for $post_ID coming from in this statement?
$parentpost_id = wp_get_post_parent_id( $post_ID );