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:

    $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.