Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #207718

    Hi,
    Anyone knows how to sort posts in category/archive in alphabetical order?

    Thanks
    M

    #207836

    Hey motylanogha!

    Edit config-templatebuilder > avia-shortcodes > blog.php, find this code on line 297:

    $query = array(	'paged' 	=> $page,
    									'posts_per_page' => $params['items'],
                                        'offset' => $params['offset'],
                                        'post__not_in' => (!empty($no_duplicates)) ? $avia_config['posts_on_current_page'] : array(),
    									'tax_query' => array( 	array( 	'taxonomy' 	=> $params['taxonomy'],
    																	'field' 	=> 'id',
    																	'terms' 	=> $terms,
    																	'operator' 	=> 'IN')));
    				}
                    else
    				{
    					$query = array(	'paged'=> $page,
                                        'posts_per_page' => $params['items'],
                                        'offset' => $params['offset'],
                                        'post__not_in' => (!empty($no_duplicates)) ? $avia_config['posts_on_current_page'] : array(),
                                        'post_type' => $params['post_type']);
    				}

    Replace it with:

    $query = array(	'paged' 	=> $page,
    									'posts_per_page' => $params['items'],
    									'orderby' => 'name', 'order' => 'ASC',
                                        'offset' => $params['offset'],
                                        'post__not_in' => (!empty($no_duplicates)) ? $avia_config['posts_on_current_page'] : array(),
    									'tax_query' => array( 	array( 	'taxonomy' 	=> $params['taxonomy'],
    																	'field' 	=> 'id',
    																	'terms' 	=> $terms,
    																	'operator' 	=> 'IN')));
    				}
                    else
    				{
    					$query = array(	'paged'=> $page,
                                        'posts_per_page' => $params['items'],
    									'orderby' => 'name', 'order' => 'ASC',
                                        'offset' => $params['offset'],
                                        'post__not_in' => (!empty($no_duplicates)) ? $avia_config['posts_on_current_page'] : array(),
                                        'post_type' => $params['post_type']);
    				}

    Refer to this link for more order parameters: http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters

    Best regards,
    Ismael

    #208149

    Thanks Ismael but I can see no affect.

    I’ve added the following action to functions.php which made me happy:

    function order_category_archives( $query ) {
      if ( is_category() && $query->is_main_query() ){ // is_category() can specify a category, if necessary
        $query->set( 'orderby', 'title' );
        $query->set( 'order', 'ASC' );
      }
    }
    
    add_action( 'pre_get_posts', 'order_category_archives' );
    #208332

    Hi!

    Glad you found a fix. :)

    Regards,
    Ismael

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Listing blog posts in alphabetical order’ is closed to new replies.