wordpress get random posts from category

In wordpress widget or on homepage, In wordpress get random posts from category. Here in wordpress tutorial we have given some nice tricks and tips for wordpress developers. There are many ways to achieve this. I can recommend to use Page Builder Plugin and use smart posts widget plugin.

wordpress get random posts from category

Above plugin will not add any database table to your wordpress website. We prefer to use the above plugin. Using smart posts widget plugin, you can show random post with simple setting or configuration.

Still you want to show random post by using code than use following code.

 

$query_params="post_type=post&showposts=10&cat=12&orderby=rand&order=DESC";
$smart_posts = new WP_Query($query_params);

while ( $smart_posts->have_posts() )
{
$smart_posts->the_post();
?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<?php the_post_thumbnail(); ?>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;</a>
<?php the_excerpt(); ?> 

<?
}
wp_reset_postdata();


 

 

Features of Plugin which shows every types of posts.

Smart Posts Widget

wordpress get random posts from category
wordpress get random posts from category

 

Smart Posts Widget – is designed to show your posts as you want without any programming knowledge. display all type of post types from a certain post type or post category or post tags.

There are many options for user to filter or order posts. You can able to select many options to choose your posts.

Smart Posts Widgets developed to provide very easy to user for displaying all types of posts within your widget areas.

widget is compatible with Page Builder. You can create beautiful page layouts and show posts as per your choice.

how to get random posts in wordpress

Wordpres tutorial, how to get random posts in wordpress. Many times we need the random post from wordpress. Like for old tweet or if you want random posts.  Like for old tweet or if you want to show random posts on home page. That is very easy wordpress provided simple method for this.

how to get random posts in wordpress

You just need to add the following query post code before loop.


 <?php query_posts(array('orderby' => 'rand')); ?>

//post data code will go here.

This way can easily show the random posts on home page.

Above is manual method for showing random posts in wordpress. If you want to show random posts using wordpress plugin than use smart widget post.

how to get random posts in wordpress