Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #268693

    I have followed the instructions here:

    http://www.kriesi.at/support/topic/how-to-sort-avia-blog-post-element-posts-alphabetically/

    and inserted this code into my child theme’s functions.php file:

    add_filter('avia_post_slide_query','avia_order_by_random', 10, 2);
    function avia_order_by_random($query, $params)
    {
    $query['orderby'] = 'title';
    $query['order'] = 'ASC';
    return $query;
    }

    However, the posts are being sorted by title only on each page. The query seems to be grabbing the first 9 posts chronologically for page 1, then sorting them by title within that page. When I go to page 2, it’s the next 9 posts chronologically, etc. Is this how it is intended to work? What I need is for the entire set to be sorted by title so that the A’s are on the first page and the Z’s are on the last page.

    Test site is here:

    http://test.promocookiecutters.com/examples/

    #268775

    Hi Scott!

    Have you setting the element to show ALL the posts with no pagination?

    Regards,
    Josue

    #268844

    No, because I want pagination. But I need the posts to sort before they are paginated, which is what I expected. That’s how it works if I code a query manually.

    #268846

    Sadly that won’t work, WordPress creates an individual query every time a page is requested. Another workaround would be to re-order them with a plugin like:

    https://wordpress.org/plugins/post-types-order/

    Regards,
    Josue

    #268857

    Thanks for the suggestion. In the end, this code gave me what I needed, defaulting all queries to sort by title. And this sort happens regardless of whether or not I use pagination.

    add_filter( 'pre_get_posts', 'custom_get_posts' );
    function custom_get_posts( $query ) {
    
      if( is_category() || is_archive() ) { 
        $query->query_vars['orderby'] = 'name';
        $query->query_vars['order'] = 'ASC';
      }
        return $query;
    }
    #268859

    Glad you found a solution, thanks for sharing it Scott :)

    Best regards,
    Josue

Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘How to sort avia blog post element grid posts alphabetically’ is closed to new replies.