Hi @shandysuta!
I checked the code from the mentioned topic, and it’s still working as expected. It correctly sorts products by date. Please ensure the following:
- The code is placed in the functions.php file of your child theme or added as a Snippet in the Code Snippets plugin.
- You are using the free version of FiboSearch, as this code does not work in the premium version.
If the above code still doesn’t work for you, try this alternative:
add_filter( 'dgwt/wcas/search_results/output', function( $output ) {
if ( isset( $output['suggestions'] ) ) {
usort( $output['suggestions'], function ( $a, $b ) {
if ( isset( $a['type'] ) && $a['type'] == 'product' &&
isset( $b['type'] ) && $b['type'] == 'product' ) {
$date_a = get_post_field( 'post_date', $a['post_id'] );
$date_b = get_post_field( 'post_date', $b['post_id'] );
return strtotime( $date_b ) - strtotime( $date_a );
}
return 0;
} );
}
return $output;
} );
The implementation process remains the same as described above.
Best regards,
Kris