Created
December 4, 2019 09:17
-
-
Save ilicfilip/21f503ca6f45a8ae24f7c6e99607ec2c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fusion_get_related_posts( $post_id, $number_posts = -1 ) { | |
$args = ''; | |
$number_posts = (int) $number_posts; | |
if ( 0 === $number_posts ) { | |
$query = new WP_Query(); | |
return $query; | |
} | |
$args = wp_parse_args( | |
$args, | |
array( | |
'orderby' => 'rand', | |
'ignore_sticky_posts' => 0, | |
'posts_per_page' => $number_posts, | |
'post__not_in' => array( $post_id ), | |
) | |
); | |
// If placeholder images are disabled, | |
// add the _thumbnail_id meta key to the query to only retrieve posts with featured images. | |
if ( ! Avada()->settings->get( 'featured_image_placeholder' ) ) { | |
$args['meta_key'] = '_thumbnail_id' | |
} | |
return fusion_cached_query( $args ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'fusion_related_posts_query_args', function( $args ) { | |
// Remove same categories condition. | |
unset( $args['category__in'] ); | |
// Set orderby to random. | |
$args['orderby'] = 'rand'; | |
return $args; | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment