wp query – Prevent WordPress loop from displaying similar post titles

Question

How can I prevent WordPress loop from displaying similar post titles?

eg.

The main post title is: Steady content

But if the array $posts_ids has a post with the title: We have some steady content, my code repeats twice this post inside the output content…

I’m using this snippet to have a second loop inside my post. Let me explain:

I have a custom field here I store all the posts ID’s that I like to call in this loop

$posts_ids = get_post_meta($post_id, 'posts_ids', true);

Then I build the args

$arrayIds = explode(',', $posts_ids);
$args = array('post_type' => 'post','post__in' => $arrayIds, 'ignore_sticky_posts' => 1);

$temp = $custom_query;
$custom_query= null;
$custom_query = new WP_Query( $args );

Then I start the second loop on the post after the the_content

if($custom_query->have_posts()) : while ($custom_query->have_posts()) : $custom_query->the_post();
        // My custom HTML here          
    endwhile;

    wp_reset_postdata(); 
    
    else: 
    
    endif;

0
bpy 4 weeks 2022-08-30T14:52:19-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse