Viewing 1 replies (of 1 total)
  • 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:

    1. The code is placed in the functions.php file of your child theme or added as a Snippet in the Code Snippets plugin.
    2. 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

Viewing 1 replies (of 1 total)

The topic ‘Sort Ajax search result by date – previous code don’t work’ is closed to new replies.