WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] my single-custom_postytype is showing all posts content

[Resolved] my single-custom_postytype is showing all posts content

  • my single-custom_postytype is showing all posts content, not the one post content I am currently viewing.

    blogurl/products/productone

    is showing all the posts contents.

    <?php
        $args = array( 'post_type' => 'acme_product' );
        $loop = new WP_Query( $args );
        while ( $loop->have_posts() ) : $loop->the_post(); ?>
    
        <h2><?php echo the_title(); ?></h2>
        <hr />
    
        <?php echo the_content(); ?>
    
        <?php endwhile; ?>
        <?php wp_reset_query(); ?>

    any ideas?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator keesiemeijer

    @keesiemeijer

    if you’re using a single-{post_type}.php template for single posts of your custom post type you don’t need to query the loop. Try it with this in your single-acme_product.php:

    <?php while ( have_posts() ) : the_post(); ?>
    
    <h2><?php echo the_title(); ?></h2>
    <hr />
    
    <?php echo the_content(); ?>
    
    <?php endwhile; ?>
    <?php wp_reset_query(); ?>

    just realized that, seems I wasn’t paying attention to this.
    thanks for the fast reply @keesiemeijer !

    Moderator keesiemeijer

    @keesiemeijer

    No problem 🙂
    I’m glad you’ve got it resolved.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Resolved] my single-custom_postytype is showing all posts content’ is closed to new replies.
Skip to toolbar