This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

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 ?

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

    Hello,

    I try to remove duplicated product via customfield to result, I use this:

    [php]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;
    }[/php]

    But no effect… can you help me ?

    Thanks

    #17526
    Ernest MarcinkoErnest Marcinko
    Keymaster

    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.

    #17528
    ilanbilanb
    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
    ilanbilanb
    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
    Ernest MarcinkoErnest Marcinko
    Keymaster

    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!

    #17532
    ilanbilanb
    Participant

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

    #17533
    Ernest MarcinkoErnest Marcinko
    Keymaster

    You cannot access this content.

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.