So, as a starter to my new series of posts, all for handy little copy and paste code snippets, I thought I’d start with an easy one: How to get custom post type by ID.
It’s a simple as:
<?php $the_query = new WP_Query( ‘post_type=custom_post_type&p=1‘ ); ?>
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
<?php the_content () ?>
<?php endwhile; ?>
To get custom post type by ID, make sure to edit the “1” under p= to your ID and make sure you change “custom_post_type” to your custom post type name.
Are you having trouble? If so, make sure you check out the Codex by WordPress: https://codex.wordpress.org/Class_Reference/WP_Query or, comment on this post and I’ll see if I can help!
Don’t forget to share or reference this in the forums if you come across the same issue.
I’ve been a freelance web designer since the age of 10 and I’ve learnt a few things along the way. I’ve been brought up with the internet and how to create with it. From this, I’ve got over 12 years experience in the web design industry which is unique.
Now I specialise in WordPress and responsive web design. I chose WordPress as it is the most user friendly and diverse CMS system out there and everything I make is responsive as standard. As a freelance web designer, I’m always looking at staying ahead of the game.