jcadima
3/29/2016 - 7:04 PM

wp_query ordered by post ID but not date

wp_query ordered by post ID but not date


https://wordpress.org/support/topic/wp_query-ordered-by-post-id-but-not-date

<?php
  $args=array(
    'category__not_in' => 1,
    'post_type' => 'post',
    'post_status' => 'publish',
    'posts_per_page' => -1,
    'orderby'=> 'id',
    'order' => 'desc',
    'ignore_sticky_posts' => 1
  );
  $my_query = null;
  $my_query = new WP_Query($args);
  if( $my_query->have_posts() ) {
    while ($my_query->have_posts()) : $my_query->the_post(); ?>
      <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
      <?php
      echo 'post id: ',$post->ID;
    endwhile;
  }
?>