• Resolved JCLondon

    (@jclondon)


    Hi there,

    Would it be possible to exclude products from the search results that are older than a certain date? Perhaps products created before a specific day/month/year?

    I am using the PRO version.

    Thanks
    Jeff

    • This topic was modified 5 years, 10 months ago by JCLondon.
Viewing 1 replies (of 1 total)
  • Plugin Author ILLID

    (@mihail-barinov)

    I found the solution for you. But you will need to make some little changes in the plugin source code.I will also add them with the next plugin release.
    So please open advanced-woo-search/includes/class-aws-search.php file, find line

    $this->data['sql'] = $sql;

    and replace it with

    $sql = apply_filters( 'aws_search_query_string', $sql );
    $this->data['sql'] = $sql;

    After please use following code snippet

    add_filter( 'aws_search_query_array', 'my_aws_search_query_array' );
    function my_aws_search_query_array( $query ) {
     global $wpdb;
    
     $date = '2014-01-01 00:00:00';
    
     $table = $wpdb->prefix . AWS_INDEX_TABLE_NAME;
    
     $query['select'] = str_replace( 'ID', $table . '.ID', $query['select'] );
     $query['search'] .= "AND {$table}.ID = {$wpdb->posts}.ID AND {$wpdb->posts}.post_date > STR_TO_DATE('{$date}', '%Y-%m-%d %H:%i:%s')";
    
     return $query;
    }
    
    add_filter( 'aws_search_query_string', 'my_aws_search_query_string' );
    function my_aws_search_query_string( $sql ) {
     global $wpdb;
     $sql = str_replace( 'FROM', 'FROM ' . $wpdb->posts . ',', $sql );
     return $sql;
    }

    replace ‘2014-01-01 00:00:00’ with the needed date. In the search results you will see only products that are no older than this date.

    You need to add it somewhere outside the plugins folder. For example, inside functions.php file of your theme or use some plugin for adding code snippets.
    Also after adding this code you will need to go to the plugin settings page and click ‘Clear cache’ button.

Viewing 1 replies (of 1 total)

The topic ‘Exclude products older than date’ is closed to new replies.