-
AuthorPosts
-
November 17, 2018 at 7:54 pm #1034780
I’d like to be able to select a category (I know how to do that one), but instead of having only the same posts listed in order, have a random selection show.
Is this an easy thing to do? It’s not a deal breaker at all.
Thanks,
JonNovember 17, 2018 at 10:59 pm #1034791Hey gatehealing,
To show your blog posts randomly on your site, when using the blog posts element, Try adding this code to the end of your functions.php file in Appearance > Editor:add_filter('avia_blog_post_query', 'avia_modify_post_grid_query_rand'); function avia_modify_post_grid_query_rand( $query ) { $query['orderby'] = 'rand'; return $query; }
This was found at the Blog Post element documentation
Best regards,
MikeNovember 18, 2018 at 2:43 am #1034811Thanks Mike,
Reading through that documentation to get this fully set up since the code itself didn’t do it.I’ll check back once I’ve got it dialed in.
J- This reply was modified 6 years, 1 month ago by gatehealing.
November 18, 2018 at 4:11 am #1034817Hi,
If the code didn’t work, check that the quotes didn’t turn into curly quotes when you copied the code.Best regards,
MikeNovember 18, 2018 at 4:44 am #1034818Assuming the single quote ‘ is what I am supposed to see, I double checked and replaced all of them with that, still does not work. Weird.
J
November 18, 2018 at 8:23 pm #1034890Hi,
I have tried a few solutions on my localhost & found this a little trickier than expected, but I found this one to show the post randomly:add_filter('avia_post_slide_query','avia_order_by_random', 10, 2); function avia_order_by_random($query, $params) { $query['orderby'] = 'title'; $query['orderby'] = 'rand'; return $query; }
and this one to show the blog posts randomly within a category.
add_filter('avia_post_slide_query','avia_order_by_random', 10, 2); function avia_order_by_random($query, $params) { $query['orderby'] = 'title'; $query['order'] = 'rand'; $terms = explode(',', $params['categories']); if (!empty($terms) && in_array(1, $terms)) { $query['orderby'] = 'date'; } return $query; }
the “1” is the category, please adjust to suit.
Best regards,
MikeNovember 19, 2018 at 1:56 am #1034964That top code did it. And it works with pagination.
Thanks!
JonNovember 19, 2018 at 3:03 am #1034971Hi,
Glad we were able to help, we will close this now. Thank you for using Enfold.For your information, you can take a look at Enfold documentation here
For any other questions or issues, feel free to start new threads under Enfold sub forum and we will gladly try to help you :)Best regards,
Mike -
AuthorPosts
- The topic ‘Blog Post Content Element used on Page: Possible to randomize posts that appear?’ is closed to new replies.