custom post type loop mashing post data with most recent submission
-
Output for my custom post type loop went loopy and started to mix and match the custom post type metadata fields with the standard post content from the most recently added custom post type.
Are you confused yet?
Clarifying, all the custom fields were picking up the content associated with get_the_id() but the author, posted comments, and content were associated with the post id of the most recent entry.
Through research, trial and error, I discerned that the post ID was changing in the while part of the loop. I was crosseyed from staring at the code so I requisitioned another set of eyes. They couldn’t see the problem either but they put me onto the setup_postdata function so I pursued this tack.
I found this link that provided a solution:
https://wordpress.stackexchange.com/questions/30694/manually-set-global-post-vars-with-an-id-in-order-to-use-template-tagsThe code now works with
while ($my_query->have_posts()) : $my_query->the_post(); global $post; $post = get_post( $postID, OBJECT ); setup_postdata( $post ); ... do stuff ... endwhile; wp_reset_postdata();
The challenge now is that the post id integer is displaying on the page. This isn’t working for me either but everything I’ve tried to squash that is not resulting in the desired effect.
I have the entire script (unvarnished) up here if you want to see all the logic involved: https://pastebin.com/vfvbx853
Since functionality is more important than layout styling here, please disregard the messy layout and styling but, for those who like to see things online, here is a live link so you can see the issue:
https://creativeconundrum.com/arts/portfolio/revolution/
The “140” beneath the post title of that page should not be there.
Thank you, in advance, for applying your thought energy to my issue because, as I alluded to before, I’m cross eyed from staring at this code and I’m totally out of ideas.
I recognize that there is a problem with the while loop code and I also recognize that my solution is a less-than-elegant hack that has potential to introduce potential fragility but I still need to forge ahead here.
I am reaching out for help now. I will accept and try any recommended solutions and report back but, for now, my question is:
How can I suppress the display of the object ID with my current functioning (albeit limping) code?
- The topic ‘custom post type loop mashing post data with most recent submission’ is closed to new replies.