Filter result, remove duplicated result custom field ?

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

 
Keymaster
3 years, 9 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #17519

    Participant

    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

    #17526

    Hi,

    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 :)


    #17528

    Participant

    Hello,

    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

    #17529

    Participant

    Workflow:

    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 🙂

    #17531

    Okays, 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.
    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!

    Best,
    Ernest Marcinko

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


    #17532

    Participant

    Thanks Ernest !!! work perfect 🙂
    Save my day thanks again, very powerfull plugin

    #17533
    You cannot access this content. Best,
    Ernest Marcinko

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


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

You must be logged in to reply to this topic.