Get custom post type by ID

Posted on March 31, 2015 8:07 pm in
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on LinkedIn0

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: 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.

Share on Facebook0Tweet about this on TwitterShare on Google+0Share on LinkedIn0
< Previous Post
Next Post >

Leave a Reply

Your email address will not be published. Required fields are marked *

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.

I specialise in responsive Wordpress websites and pixel perfect designs.
"The product has turned out to be truly unique and exactly what I wanted, both aesthetically and functionally. I cannot begin recommending him enough for any developing project, he's just the best!"
Katy Kann
View Project
Let's make your vision come to life
I've put together an easy form to get us started
Freelance Web Designers in the UK