Support » Plugin: Related Posts by Taxonomy » Display all posts randomly

  • Resolved blaivas


    Hello there,

    I simply want to display other posts within the post. But all posts, not only posts from the Category in which the current post is.
    I thought this [related_posts_by_tax related=”false”] shortcode does that, but it still displays posts only from the category from which the current post is.

    Any shortcode to display ALL posts, including other categories? Like 5 random posts?


Viewing 1 replies (of 1 total)
  • Plugin Author keesiemeijer


    Hi blaivas

    If related is set to false it displays related posts by post date, instead of by terms in common. But they are still related by the terms.

    You could get your own related posts with this filter

    Put this in your functions.php file.

    add_filter( 'related_posts_by_taxonomy_pre_related_posts', 'rpbt_override_related_posts', 10, 2 );
    function rpbt_override_related_posts( $related_posts, $args ) {
    	// Use widget or shortcode settings for our own query.
    	$post_args = array(
    		'post_type' => $args['post_types'],
    		'posts_per_page' => $args['posts_per_page'],
    		'orderby' => 'rand',
    	// Format thumbnails needs a meta query for posts with post thumnails.
    	if ( 'thumbnails' === $args['format'] ) {
    		$post_args['meta_query'] = array(
    				'key' => '_thumbnail_id',
    	$my_related_posts = get_posts( $post_args );
    	return $my_related_posts;

    This will get random posts with the WordPress function get_post()

    I’m sure there are plugins that do this out of the box for you.

Viewing 1 replies (of 1 total)
  • The topic ‘Display all posts randomly’ is closed to new replies.