Skip to main content
Bumped by Community user
added 21 characters in body
Source Link
gmazzap
  • 46.3k
  • 6
  • 95
  • 147

multiple Multiple loops with outwithout repeating content

I have a second loop on a page where I want to display posts from the same category as the present post but excluding the present post. 

I have a loop that displays all the posts from the same category as the current post, but dosedoes not exclude the current post. Can you help me exclude the current post?

  <?php
  $project_category = wp_get_post_categories($post->ID); 
  $postid = $post->ID;
  ?>

  <?php
  $the_query = new WP_Query( array(
      'category__in' => $project_category,
      'posts_per_page' => -1,
      'post__not_in' => $postid,
  ) );
  ?> 

  <?php                                                      
  $loop = new WP_Query( $the_query );
  while ( $loop->have_posts() ) : $loop->the_post();  
  ?>
$project_category, 'posts_per_page' => -1, 'post__not_in' => $postid, ));?> have_posts() ) : $loop->the_post(); ?>

multiple loops with out repeating content

I have a second loop on a page where I want to display posts from the same category as the present post but excluding the present post. I have a loop that displays all the posts from the same category as the current post but dose not exclude the current post. Can you help me exclude the current post?

<?php
  $project_category = wp_get_post_categories($post->ID); 
  $postid = $post->ID; ?>
$project_category, 'posts_per_page' => -1, 'post__not_in' => $postid, ));?> have_posts() ) : $loop->the_post(); ?>

Multiple loops without repeating content

I have a second loop on a page where I want to display posts from the same category as the present post but excluding the present post. 

I have a loop that displays all the posts from the same category as the current post, but does not exclude the current post.

  <?php
  $project_category = wp_get_post_categories($post->ID); 
  $postid = $post->ID;
  ?>

  <?php
  $the_query = new WP_Query( array(
      'category__in' => $project_category,
      'posts_per_page' => -1,
      'post__not_in' => $postid,
  ) );
  ?> 

  <?php                                                      
  $loop = new WP_Query( $the_query );
  while ( $loop->have_posts() ) : $loop->the_post();  
  ?>
Source Link

multiple loops with out repeating content

I have a second loop on a page where I want to display posts from the same category as the present post but excluding the present post. I have a loop that displays all the posts from the same category as the current post but dose not exclude the current post. Can you help me exclude the current post?

<?php
  $project_category = wp_get_post_categories($post->ID); 
  $postid = $post->ID; ?>
$project_category, 'posts_per_page' => -1, 'post__not_in' => $postid, ));?> have_posts() ) : $loop->the_post(); ?>