Default natural order issue

Rodrigo T. asked 4 years ago

Hi Dave.

I was unable to remove sort options, because of instead of defaulting to most recent first (normally sort by Date DESC), it shows the oldest products first.

Ideally, I would prefer to have it as ID DESC.

Any ideas on what could be done?

1 Answers
Dave Hilditch Staff answered 4 years ago

If you need a particular sort order, then do not use the ‘remove sort options’ in Scalability Pro as this will use the ‘default sort order’ – the default sort order is whatever order they appear in the index or the table, depending on whether a table scan or index seek occurred. Removing the sort options is normally useful for very large product sites with millions of products.

To change your sort order to by ID DESC, you’ll need to add some custom code – something like this to your functions.php file:

function WPIorderpostsbyID( $query ) { 

if ( $query->is_home() && $query->is_main_query() ) {

$query->set( 'orderby', 'ID' );

$query->set( 'order', 'DESC' );

}

}

add_action( 'pre_get_posts', 'WPIorderpostsbyID' );

Your Answer


Super Speedy Plugins
Logo