Title: Display all posts randomly
Last modified: March 14, 2018

---

# Display all posts randomly

 *  Resolved [blaivas](https://wordpress.org/support/users/blaivas/)
 * (@blaivas)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/display-all-posts-randomly/)
 * 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?
 * Thanks

Viewing 1 replies (of 1 total)

 *  Plugin Author [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/display-all-posts-randomly/#post-10082719)
 * 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
    [https://keesiemeijer.wordpress.com/related-posts-by-taxonomy/filters/#related_posts_by_taxonomy_pre_related_posts](https://keesiemeijer.wordpress.com/related-posts-by-taxonomy/filters/#related_posts_by_taxonomy_pre_related_posts)
 * 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(
       			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()`
    [https://developer.wordpress.org/reference/functions/get_posts/](https://developer.wordpress.org/reference/functions/get_posts/)
 * I’m sure there are plugins that do this out of the box for you.
    [https://wordpress.org/plugins/display-posts-shortcode/](https://wordpress.org/plugins/display-posts-shortcode/)

Viewing 1 replies (of 1 total)

The topic ‘Display all posts randomly’ is closed to new replies.

 * ![](https://ps.w.org/related-posts-by-taxonomy/assets/icon.svg?rev=1115231)
 * [Related Posts by Taxonomy](https://wordpress.org/plugins/related-posts-by-taxonomy/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/related-posts-by-taxonomy/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/related-posts-by-taxonomy/)
 * [Active Topics](https://wordpress.org/support/plugin/related-posts-by-taxonomy/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/related-posts-by-taxonomy/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/related-posts-by-taxonomy/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * Last activity: [8 years, 2 months ago](https://wordpress.org/support/topic/display-all-posts-randomly/#post-10082719)
 * Status: resolved