Third party themes are off topic, but I ended up checking it anyway:
The Problem
What comes before & after your posted code is important:
Before:
// Return array of cached results if they exist.
$featured_ids = get_transient( 'featured_content_ids' );
if ( ! empty( $featured_ids ) ) {
return array_map( 'absint', (array) $featured_ids );
}
After:
// Ensure correct format before save/return.
$featured_ids = wp_list_pluck( (array) $featured, 'ID' );
$featured_ids = array_map( 'absint', $featured_ids );
set_transient( 'featured_content_ids', $featured_ids );
This means your theme is caching the featured post IDs, through the Transients API.
So randomizing will not work like you expected.
The default TTL is 0, meaning it will never expire, until it's deleted by hand.
Workarounds
Here are four different methods:
Method 1)
Instead, modify this in Featured_Content::get_featured_posts()
:
$featured_posts = get_posts( array(
'include' => $post_ids,
'posts_per_page' => count( $post_ids ),
) );
to:
$featured_posts = get_posts( array(
'include' => $post_ids,
'posts_per_page' => count( $post_ids ),
'orderby' => 'rand'
) );
within your child theme.
Method 2)
We could also shuffle the posts with the longform_get_featured_posts
filter:
add_filter( 'longform_get_featured_posts', function( $posts )
{
shuffle( $posts );
return $posts;
}, 11 );
Method 3)
We could modify the orderby
within the pre_get_posts
hook:
add_action( 'pre_get_posts', function( $q )
{
if(
did_action( 'longform_featured_posts_before' )
&& ! did_action( 'longform_featured_posts_after' )
)
$q->set( 'orderby', 'rand' );
}, 99 );
between the longform_featured_posts_before
and longform_featured_posts_after
hooks.
Method 4)
We could try to increase the theme's quantity
option (from the backend) to 6 but display only 4 (just as an example). We could then use a modification of method #2:
add_filter( 'longform_get_featured_posts', function( $posts )
{
shuffle( $posts );
if( count( $posts ) > 4 )
$posts = array_slice( $posts, 0, 4 );
return $posts;
}, 11 );
To increase the number above 6
, then max_posts
need to be modified from this code part:
// Add support for featured content.
add_theme_support( 'featured-content', array(
'featured_content_filter' => 'longform_get_featured_posts',
'max_posts' => 6,
) );
Many other variations could be possible, but I stop here ;-)
Note that I've never installed or used this theme before. These are just some ideas based on skimming through the theme's source code.