• Hi,
    i’m trying to sort posts by Views in categories
    but when i put this code in category.php , the posts are sorted by views but from diffrent categories, i just want to sort them by the current category

    <?php
    query_posts("meta_key=views&&orderby=meta_value_num&order=DES");
     while (have_posts()) : the_post();
     // the code
    endwhile;
    ?>

    thanks

Viewing 1 replies (of 1 total)
  • Thread Starter Wasim alhajebi

    (@wassimo)

    Here is the correct code may someone of you need to use it

    <?php
    $args = array(
        'paged' => $paged,
        'meta_query'=> array(
            array()),
        'meta_key'=>'views',
        'orderby'=>'meta_value_num',
        'order'=>'DESC');
    $args = array_merge( $args , $wp_query->query );
    $posts = query_posts( $args );
    foreach( $posts as $post ) {
    
    // the code
    }
    ?>

Viewing 1 replies (of 1 total)
  • The topic ‘Query problems in category’ is closed to new replies.