Home › Forums › Backend Issues (wp-admin) › Post Object at random › Reply To: Post Object at random
I guess I can better use a repeater field as well then. One to basically load post slides using array_rand()
I do not need a radio select box like in the example.
I would need to use a loop and load a post at random. A basic repeater field example in the ACF Repeater Field tutorial shows how to load a sub field value from a random row of a Repeater field:
<?php
$rows = get_field('repeater_field_name' );
if( $rows ) {
$index = array_rand( $rows );
$rand_row = $rows[ $index ];
$rand_row_title = $rand_row['title'];
// Do something...
}
This loop is close to what I need, but I would need to “just” load a random post from a taxonomy from the last 3-4 months.
Perhaps I just need an ACF block, in it do a new WP_Query
to load custom post type at random from a date range. Will need to think about this more.
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.