0
votes

Does anyone have ever seen this?

When we're accessing one of wordpress category post here:

On the top item, it's not the latest posted article instead it's the oldest one.

enter image description here

Which part of the php code should be changed ? It's for wordpress version of 4.5 from this link.

1
Are you using custom query or just defaul archieve or category page and please share your template code so i can help you.raju_odi
paste this in function.php.............. function change_category_order( $query ) { $category = get_queried_object(); $cat_id=$category->term_id; if ( $query->is_category($cat_id) && $query->is_main_query() ) { $query->set( 'order', 'DESC' ); } } add_action( 'pre_get_posts', 'change_category_order' );Vaibhav Kumar
which file should be changed? I just use the template no files were changed previously except the template only. @TechnoDevisergumuruh
in your theme function.php just paste the above code. from "function to last ".Vaibhav Kumar

1 Answers

0
votes
 function change_category_order( $query ) {
 $category = get_queried_object(); 
  $cat_id=$category->term_id;
  if ( $query->is_category($cat_id) && $query->is_main_query() ) { 
  $query->set( 'order', 'DESC' ); 
  } 
  } 
 add_action( 'pre_get_posts', 'change_category_order' );

If you use any custom query add this also in post loop 'order' => 'DESC'

     $args = array(
    'post_type' => 'post',
    'order' => 'DESC',  );

    $q = new WP_Query($args);

or paste this in function.php

   add_action( 'pre_get_posts', 'my_change_sort_order'); 
     function my_change_sort_order($query){
     if(is_archive()):
     //If you wanted it for the archive of a custom post type use:          is_post_type_archive( $post_type )
       //Set the order ASC or DESC
       $query->set( 'order', 'DESC' );
       //Set the orderby
       //$query->set( 'orderby', 'title' );
    endif;    
};