• Resolved Jonathan

    (@bionicsquid)


    I’ve got a custom post type with custom fields in active development. All of a sudden I’ve got a problem where only the most recent post is displayed, even though the URL changes appropriately to reflect the post URL that should be displayed. Changing the published date of other posts will change the post being displayed to the most current, while manually changing the browser’s URL still shows that most recent post.

    The query and loop I’m using in my template are at https://pastebin.com/vagdrnFW and I would so appreciate any help.

Viewing 3 replies - 1 through 3 (of 3 total)
  • $args = array ( ‘post_type’ => ‘products’, ‘posts_per_page’ => ‘1’ , );

    That line of code is telling the WordPress to only display 1 post per page. You have no sorting code (ORDER BY) so it is only going to display the most recent custom post you have added.

    Thread Starter Jonathan

    (@bionicsquid)

    Thanks Bob. This is intended to be a single post, so I’ve edited single.php and content-single.php to be single-product.php and content-single-product.php. The goal here is to display a single post per page, and not to display the most recent post. It sounds like if I use ORDER BY it won’t address that problem. As I say, the url changes appropriately as I click links to the posts, but the actual post displayed is the same over and over on these pages – the most recent. Maybe I’m wrong here – please advise.

    Thread Starter Jonathan

    (@bionicsquid)

    I just solved this, it seems, but deleting the $args code entirely and just using a standard loop. Post are now showing as they should, I guess bc WordPress is seeing the template it wants for products and using that. Apparently it never needed to be told to use the custom post type ‘products’ in the first place, which is what my $args were telling it to use. If anyone has input here as to why this code isn’t needed after all I’d be grateful.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom Post Type Display Only Shows Most Recent Post’ is closed to new replies.