Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #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,
    Jon

    #1034791

    Hey 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,
    Mike

    #1034811

    Thanks 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

    #1034817

    Hi,
    If the code didn’t work, check that the quotes didn’t turn into curly quotes when you copied the code.

    Best regards,
    Mike

    #1034818

    Assuming 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

    #1034890

    Hi,
    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,
    Mike

    #1034964

    That top code did it. And it works with pagination.

    Thanks!
    Jon

    #1034971

    Hi,
    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

Viewing 8 posts - 1 through 8 (of 8 total)
  • The topic ‘Blog Post Content Element used on Page: Possible to randomize posts that appear?’ is closed to new replies.