Search code examples
phpwordpressurlpermalinks

WordPress: change a tag's url and order by date in ascending manner


I have the following tag in my WordPress site:

http://www.example.com/tag/collection-100

and I want to change the tag's url to http://www.example.com/legends as well as make the posts displayed on that page to be ordered by date in ascending manner at the moment they are displayed in a descending way.

I've searched for plugin which can do this but I couldn't find anything on WordPress' site.

I've also tried creating a new template and using the following code in it:

query_posts( 'tag=collection-100&order=ASC' );

which fetches the first 18 posts but the pagination doesn't work properly and instead it always shows the first 18 posts.

Any help much appreciated : )


Solution

  • Create a custom template like this "example-template.php" and write your query like this:

    get_header();
    
    $loop = new WP_Query( array( 'post_type' => 'your-post-type',  'orderby' => 'date', 'order' => ASC ) ); 
    
    while ( $loop->have_posts() ) : $loop->the_post(); 
        //print your needs
    endwhile;
    
    get_footer();