Vendors page sort by date from old to new

Hello,

Is there a way to change the standard sorting of the vendors inside the vendors page?
Now they are sorted by dat from new to old. But is it also possible too sort them by date from old to new?

Hope it’s possible by a snippet or something.

Thank you for your time.

Hi,

Please try this PHP snippet (How to add custom code snippets - HivePress Help Center):

add_filter( 
 'posts_orderby', 
 function($orderby, $query){
  if ( $query->get( 'post_type' ) === 'hp_vendor' && is_post_type_archive('hp_vendor') ) {
   $orderby = 'post_date ASC, ' . $orderby;
  }

  return $orderby;
 }, 
 10, 
 2 
);

Please note that it can require further customization.
If customizations are required for your site, please try customizing it using the collection of code snippets Search · user:hivepress · GitHub and other developer resources, or consider hiring someone for custom work https://fvrr.co/32e7LvY.

1 Like

Hello andrii,

Thank you so much!
This one almost work, there was a little error in the code. The ‘posts_orderby,’ should be ‘posts_orderby’ ,

The working one:

add_filter( 
 'posts_orderby', 
 function( $orderby, $query ){
  if ( $query->get( 'post_type' ) === 'hp_vendor' && is_post_type_archive('hp_vendor') ) {
   $orderby = 'post_date ASC, ' . $orderby;
  }

  return $orderby;
 }, 
 10, 
 2 
);

Thank you!

2 Likes

Hi,

Thanks for posting the solution!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.