Getting Latest Post on top (Reverse Chronological Order)

I am using the following but my posts are still in Chronological Order (Oldest to New). My target is to have latest post on the top. (Newest to Old)

$catquery = new WP_Query( array (
    'cat'=>'27', 
    'post_type'=>'news', 
    'orderby' => "post_date", 
    'order' => "DESC" ) 
);

while($catquery->have_posts()) : $catquery->the_post();

<p class="date"> <?php the_date(); ?> </p>

<h3><?php the_title(); ?></h3>

<p> <?php the_content('Read More', FALSE); ?> 

I have also tried orderby' => "date" but no luck. How to solve this?

Related posts

Leave a Reply

2 comments

  1. Your code is close, but there are a few problems.

    1. 'cat' expects an int not a string so you need 'cat'=>27,
    2. Instead of post_date you need date
    3. I’m not sure which order you need so try ASC if DESC doesn’t work.

    Here’s the new query:

    $catquery = new WP_Query(array (
      'cat'       => 27, 
      'post_type' => 'news', 
      'orderby'   => 'date', 
      'order'     => 'DESC'
    ));
    
    • order (string) – Designates the ascending or descending order of the ‘orderby’ parameter. Defaults to ‘DESC’.
      • ‘ASC’ – ascending order from lowest to highest values (1, 2, 3; a, b, c).
      • ‘DESC’ – descending order from highest to lowest values (3, 2, 1; c, b, a).

    Here’s a reference: WP_Query

  2.     your post is custom post type so use this argument:'
    
        <?php 
        $args = array(
            'tax_query' => array(
                    array(
    
                    'taxonomy' => 'news_category',
    
                    'field' => 'id',
    
                    'terms' => '27'
    
                )
            ),
            'post_type'=>'news',
            'order_by'=>'date',
            'order'=>'DESC',
            'posts_per_page'=>-1
    );
        query_posts($args);
        while ( have_posts() ) : the_post(); 
    ?>
        <li>
            <p class="date"><?php echo get_the_date('F j, Y'); ?></p>
            <a href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a>
        </li> 
    <?php 
    endwhile;
    wp_reset_query();
    ?>