WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] my single-custom_postytype is showing all posts content (4 posts)

  1. timduncan
    Member
    Posted 1 year ago #

    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?

  2. keesiemeijer
    moderator
    Posted 1 year ago #

    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(); ?>
  3. timduncan
    Member
    Posted 1 year ago #

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

  4. keesiemeijer
    moderator
    Posted 1 year ago #

    No problem :-)
    I'm glad you've got it resolved.

Topic Closed

This topic has been closed to new replies.

About this Topic