[Resolved] Unable to retrieve the_content from custom post type
So, I created a custom Post Type named “fact” and added this bit of code into the sidebar to display one randomly…
<?php $random_posts = get_posts('numberposts=2&orderby=rand&post_type=fact'); foreach( $random_posts as $post ) : ?> <?php the_title();?> <?php the_content();?> <img src="<?php the_post_thumbnail(); ?>"> <?php endforeach; ?>
…and it works almost fine. It retrieves the title of the custom post and the attached image, but “the_content” it retrieves belongs to a regular post, not the custom post type.
1) Any clues why its happening or how to fix it?
Also, while we are at it:
2) How to grab the attached image only if there is one assigned? I hate seeing and empty <img src=””> tag on the source code of the page.
- The topic ‘[Resolved] Unable to retrieve the_content from custom post type’ is closed to new replies.