SKU Search not working on newly imported and indexed products

Home Forums Product Support Forums Ajax Search Pro for WordPress Support SKU Search not working on newly imported and indexed products

This topic contains 1 reply, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 1 year, 3 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #33676
    niumalta96
    niumalta96
    Participant

    We have ajax search pro running on https://lava.mt and we have a cron to index new products being added to the site. These products are added via WooCommerce API and everything is indexing fine (product name, description, meta etc) EXCEPT FOR the SKU. The client needs to have the search work when someone types in the SKU. The strange thing is that when we do a fresh index, the SKU search works fine on all the products on WOoCommerce but when new ones are added those SKU’s are not searchable.

    Any tips on how to solve this?

    #33681
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    I assume the SKU field is added later on during the import. So the import probably creates the product, then saves it – at that point the item is already indexed. Then adds the custom field, which does not trigger the re-indexing.

    If the regular update or add post meta functions are used for the indexing, then maybe a custom code could work.

    add_action( 'updated_post_meta', 'asp_force_index_on_meta_save', 10, 2 );
    add_action( 'added_post_meta', 'asp_force_index_on_meta_save', 10, 2 );
    function asp_force_index_on_meta_save( $meta_id, $object_id ) {
    	$o = new WD_ASP_IndexTable_Action();
    	$o->update( $object_id, null, true );
    }

    Try adding this code to the functions.php file in your theme/child theme directory – make sure to have a full server back-up first for safety. For more details you can check the safe coding guidelines.

    Note, that this should only start working on new imports.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.