Home › Forums › ACF PRO › Auto Fill Related Post objects › Reply To: Auto Fill Related Post objects
Untested but here’s something to get you started:
$post_objects = get_field( 'testimonials_related' );
if ( $post_objects ) {
// your normal stuff here..
} else {
// no post objects found, query the post type for 4 random posts
// you should cache this query with either the object cache or transients api
// http://wordpress.stackexchange.com/questions/183698/way-to-cache-a-query-for-24-hrs
$current_post_id = get_the_id();
$testimonials = new WP_Query(
'post_type' => 'testimonials',
'post_status' => 'publish',
'posts_per_page' => 4,
'orderby' => 'rand',
'post__not_in' => array( $current_post_id ) // exclude the current post
);
if ( $testimonials->have_posts() ) {
while ( $testimonials->have_posts() ) {
$testimonials->the_post();
// display the posts...
}
wp_reset_postdata();
}
}
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!
Accordions are a great way to group related information while allowing users to interactively show and hide content. In this video, Damon Cook goes in-depth on how to create an accessible accordion block using ACF PRO’s Repeater field.https://t.co/RXT0g25akN
— Advanced Custom Fields (@wp_acf) March 2, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.