1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Custom product loop excluding values with same name

Discussion in 'PHP' started by kinigakos, Jan 24, 2020.

  1. #1
    Hello, I need to hide products with same title from WooCommerce shop page so i created a loop which is working and does hide products with same name but i have a problem.

    If i set posts_per_page=8 it shows less because it counts the hidden products also.
    $args = array('post_type'=>'product','posts_per_page'=>8);
    $query =new WP_Query($args);
    $list = array();
    while($query->have_posts()): $query->the_post();if(in_array(get_the_title(), $list)){continue;}
    $list[]= get_the_title();?>
    <li><?php wc_get_template_part('content','product');?></li>
    <?php endwhile;
    Code (markup):
    Any ideas?
    kinigakos, Jan 24, 2020 IP
  2. sarahk

    sarahk iTamer Staff

    Likes Received:
    Best Answers:
    Trophy Points:
    If you can't get the query to exclude the dupes then you'll need to request more than 8, take out the dupes, and then show the first 8. Creates havoc with paging so do everything you can to get the query to manage the dupes.
    sarahk, Jan 28, 2020 IP
  3. deathshadow

    deathshadow Acclaimed Member

    Likes Received:
    Best Answers:
    Trophy Points:
    You probably should't try to do this. there, corrected

    ... and people wonder why I say WP's built in database wrapping is 3i -- ignorant, incompetent, and inept. It just teaches people how NOT to do things.
    deathshadow, Feb 1, 2020 IP
    sarahk likes this.