Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Filter result, remove duplicated result custom field ?
This topic contains 6 replies, has 2 voices, and was last updated by Ernest Marcinko 5 years, 1 month ago.
- AuthorPosts
- April 15, 2018 at 8:29 pm #17519
Hello,
I try to remove duplicated product via customfield to result, I use this:
add_filter( 'asp_results', 'asp_change_result', 1, 1 ); function asp_change_result( $results ) { foreach ($results as $k=>$r ) { $cip = $product_obj['product_cip'] = get_post_meta($r->id,'product_cip'); $cip = $cip[0]; } $k = array_unique( array_diff_assoc( $cip, array_unique( $cip ) ) ); foreach ($k as $ki) { $product=array( 'post_type' => 'product', 'post_status' => 'publish', 'posts_per_page'=> -1, 'meta_query' => array( array( 'key' => 'product_cip', 'value' => $ki, 'compare'=> '=' ) ), 'fields' => 'ids', ); $a=get_posts($product); $id[] = $a[0]; } foreach ($results as $k=>$o) { foreach ($id as $a) { if ( $a == $o->id ) unset($results[$k]); } } return $results; }
But no effect… can you help me ?
Thanks
April 16, 2018 at 8:34 am #17526Hi,
Can you please describe what exactly are you trying to achieve?
If I understand correctly, you are trying to limit the results to specific IDs only? Some things are not clear to me, for example the $product_obj variable (line 6) is not defined for sure.
Feel free to describe the problem in as much details as you can, and I will try to suggest something.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
April 16, 2018 at 8:58 am #17528Hello,
I use woocommerce as market place and I have same product (same product name, same product_cip, unique ID) for many seller. If I search a product like ANDRO, product appear X time, I need to keep only one product. For that, I have created customfield “product_cip” all same product have same CIP number.
Here is screenshot: https://screencast.com/t/6IAuKGpp60
In my function, I get all product_cip and I remove duplicated to keep only one, after I need to get product ID to pass as result
Sorry if I’m not clear…
Ilan
April 16, 2018 at 9:55 am #17529Workflow:
Step1: add_filter( ‘asp_results’, ‘asp_change_result’, 1, 1 );
Step2: get all same “produc_cip” by product ID
Step3: remove duplicated product
Step4: return product to result
Mybe help to understand 🙂
April 16, 2018 at 9:49 pm #17531Okays, I think I understand now 🙂
I assume the product_cip custom field contains a single product ID (?). In that case, this custom code might do the trick.
Best,
Add this custom code to the functions.php in your theme/child theme directory (copy from line 3 only!). Before editing, please make sure to have a full site back-up just in case!
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
April 16, 2018 at 9:58 pm #17532Thanks Ernest !!! work perfect 🙂
Save my day thanks again, very powerfull pluginApril 17, 2018 at 9:10 am #17533You cannot access this content. Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
- AuthorPosts
You must be logged in to reply to this topic.