I have a Page with Custom template. In this template I have index all posts of a category with many more modification. I know i can do this by creating Category specific template but this is different and I don't want to create category based template for every category.

Everything is fine but I'm trying to achieve post order by URL on this custom page template post. ASC order by URL working on Category page but not on custom page template.

  1. Example (with custom page) : http://www.projuktiteam.com/illustrator-tutorial/?order=asc (not working)
  2. Example (with category page) : http://www.projuktiteam.com/category/video-tutorials/illustrator-tutorial/?orderby=asc (working)

I also can order ASC the posts on this custom page from loop but i want to do this by URL. Because i want to provide user to sort the post by ASC, DESC, Title, Date etc.

<?php get_header(); ?>

    <iframe class="featured-trailer" width="950" height="534" src="//www.youtube.com/embed/<?php echo get_post_meta( get_the_ID(), 'trailer', true ) ?>" frameborder="0" allowfullscreen></iframe>

<?php get_template_part('cat-featured'); ?>

</div><!-- end .carousel -->

ID, "tut-category", true); ?>

<div id="content" role="main"><?php  ?> 
<div class="loop-header">
            <h1 class="tut-cat-title"><?php echo get_the_title(); ?></h1>
            <div class="tut-cat-count"><?php echo 'Total Posts = ' . $category->count; ?></div>
        </div><!-- end .loop-header --> 

    if (have_posts()) :     

    else :

</div><!-- end #content -->

1 Answer 1


When you run an additional query, WordPress isn't going to automagically parse get vars, that only works for the main query. You have to fetch and add them manually.

Also, don't use query_posts, use WP_Query instead.

$args = array(
    'category_name' => $tutcatname,
    'posts_per_page' => 25,

if( isset( $_GET['order'] ) ){
    $args['order'] = $_GET['order'];

$query = new WP_Query( $args );
  • Thank you very much for your answer. I tried above code but that didn't work. Query function not working. So the page is showing no posts form category. This is how i pasted your code: <?php if (have_posts()) : $args = array( 'category_name' => $tutcatname, 'posts_per_page' => 25, ); if( isset( $_GET['order'] ) ){ $args['order'] = $_GET['order']; } $query = new WP_Query( $args ); get_template_part('loop-actions'); get_template_part('loop-content'); get_template_part('loop-nav'); else : ..... previous code ..... ?> Commented Nov 10, 2013 at 19:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.