I have a custom post type called "listing" and am using a template called content-own.php to display all of my listings. In that page I am using:

<a href="<?php echo str_replace( home_url(), '', get_permalink($post->ID) ); ?>

to get a link to each single listing. When I click that link it shows all of the listings on that page instead of just that single listing. The template I am using for the single listing is single-listing.php which directs to content-listing.php. There I have:

<article id="post-<?php the_ID(); ?>" <?php post_class($post-
>post_name); ?>>
  <div class="container mainPage">
    <div class="row">
      <div class="entry-content col-sm-9">
    <?php $args = array( 'post_type' => 'listing');
    $loop = new WP_Query( $args );
       while ( $loop->have_posts() ) : $loop->the_post(); ?>
           <div class="col-6 col-sm-6 box no-gutters">
             <?php sd_template_post_thumbnail();
                the_title('<h2>', '</h2>'); ?>
                <span><?php the_field('price'); ?></span>
                <span><?php the_field('description'); ?></span>
                <span><?php the_field('style'); ?></span>
                <span><?php the_field('design'); ?></span>
  <?php endwhile; ?>
</div><!--entry-content col-sm-9-->
<div class="sideContact col-sm-3">
    <?php get_sidebar(); ?>
</article><!-- #post-<?php the_ID(); ?> -->

So I'm not sure if I am doing something incorrectly with the way my templates are set up or with the loop on the content-listing.php page. Hopefully I explained this correctly, I'm fairly new to custom post types and Wordpress.

  • 1
    why are you using a custom query and loop in content-listing.php? the defaiult loop should work.
    – Michael
    Feb 26, 2018 at 0:21

1 Answer 1


If you have a single page already, you shouldn't be using a wp_query as well.

Instead of these lines:

<?php $args = array('post_type' => 'listing');
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>

Use these lines:

// Start the loop.
while ( have_posts() ) : the_post(); ?>
  • Thank you, I see now that was causing the issue, as it's new to me I didn't realize I didn't need the wp_query Feb 26, 2018 at 14:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.