• Resolved matt-tyas

    (@matt-tyas)


    For some reason I cannot understand do not duplicate is not working for me. Below is the code I am using. There are only two loops a query posts and the normal WP loop.

    Any help much appreciated!

    <?php $do_not_duplicate = array(); ?>
    
    				<!-- Featured Posts -->
    				<?php
    				  	$my_query = new WP_Query('tag=sticky&posts_per_page=3');
    				  	while ($my_query->have_posts()) : $my_query->the_post();
    				  	$do_not_duplicate = $post->ID;
    				?>
    
    				<-- Outputs three posts here-->
    
    				<?php endwhile; ?>
    
    				<!-- Normal Loop -->
    				<?php if (have_posts()) : while (have_posts()) : the_post();
    				   	   if( $post->ID == $do_not_duplicate ) continue; ?>
    
    				<-- Outputs the rest of the posts here-->
    
    				<?php endwhile; endif; ?>
    
    				<!-- But there are still duplicates? -->
Viewing 4 replies - 1 through 4 (of 4 total)
  • Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    What do you mean “is not working”, can you elaborate on that?

    Are you sure this is correct:

    if ( $post->ID == $post->ID )

    Thread Starter matt-tyas

    (@matt-tyas)

    Hi,

    By not working I mean. Rather than not duplicate posts as it should, it does duplicate posts.

    The behaviour I am looking for is:

    The normal loop shows all posts. The featured loop shows three features (I do this by tagging them as sticky – a legacy of the theme I’m redesigning). I do not want features to duplicate in the main loop but they do.

    Also excuse me if I’m not being bright (not much good with PHP) but I do not see your code example in mine above?

    Thank you for your help.

    Thread Starter matt-tyas

    (@matt-tyas)

    Thanks for your help. Inevitably that was one of those, ‘as soon as you ask you see your silly mistake’, things…

    Anyway, I’d missed:

    if (in_array($post->ID, $do_not_duplicate)) continue;

    Stupid…

    Thread Starter matt-tyas

    (@matt-tyas)

    Resolved.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Do not duplicate not working’ is closed to new replies.