• Resolved markdimi

    (@markdimi)


    In the archive view of a post type, is there a way to change the order of the posts into alphabetical order?

    Thank you

    • This topic was modified 2 years, 8 months ago by markdimi.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Theme Author Anders Norén

    (@anlino)

    Hi @markdimi,

    The order is based on the publication date of the posts. You can change the order by changing the date when you edit each post.

    — Anders

    Thread Starter markdimi

    (@markdimi)

    Hello.

    Well from what I gathered the archive uses a WP_Query object which has a setting for ordering. Isn’t there a way to externally manipulate query setting and change the order?

    Or is there a way to override the archive all together, create an archive page for the post type and rewrite the WP_Query object?

    Theme Author Anders Norén

    (@anlino)

    @markdimi You can give this plugin a try – it will set the post type to order by menu_order and allow you to drag and drop the posts to set the order.

    Thread Starter markdimi

    (@markdimi)

    Solved without overriding the archive template.

    Add the following snippet in the functions.php.

    add_action( 'pre_get_posts', 'new_sort_order'); 
    function new_sort_order($query){
    	if(is_archive() && is_post_type_archive( "post_type" )):
    		//Set the order ASC or DESC
    		$query->set( 'order', 'ASC' );
    		//Set the orderby
    		$query->set( 'orderby', 'title' );
    	endif;    
    };

    If you want to change the order to all the posts just remove is_post_type_archive from the if statement.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Change the post order in the archive view’ is closed to new replies.