Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

WP3 Post Type Question WordPress


For my new theme @ [[LINK href=""]][[/LINK]] I would like to create a portfolio page.

The theme does not use post types now, but I want to add a post type called "portfolio".

The problem is that I do not want these post types to be visible on other pages such as index.php, archive.php, only on the template page I created.

Is there anyway to remove these custom post types from the original query so that they won't be visible.

I don't want to use query_posts or WP_query to retrieve the posts on top of every page as this would create problems with archive, search or tag pages.

I guess we will need something like $post = $post - $post(post_type="portfolio")

Answers (6)


Evan Stein answers:

The default behavior is to exclude custom post types. :)

Include the custom query on your template to retrieve the custom posts.

Ant Eksiler comments:

Let me check this, do you have the code to create a custom post type?

Evan Stein comments:

Add this to your functions.php file:

function custom_portfolio_posttype() {
register_post_type( 'portfolio',
'labels' => array(
'name' => __( 'Portfolio' ),
'singular_name' => __( 'Portfolio Item' ),
'add_new' => __( 'Add New Item' ),
'add_new_item' => __( 'Add New Portfolio Item' ),
'edit_item' => __( 'Edit Portfolio Item' ),
'new_item' => __( 'Add New Portfolio Item' ),
'view_item' => __( 'View Item' ),
'search_items' => __( 'Search Portfolio' ),
'not_found' => __( 'No portfolio items found' ),
'not_found_in_trash' => __( 'No portfolio items found in trash' )
'public' => true,
'supports' => array( 'title', 'editor', 'thumbnail', 'comments' ),
'capability_type' => 'post',
'rewrite' => array("slug" => "portfolio"), // Permalinks format
'menu_icon' => get_bloginfo('template_directory') . '/images/portfolio-icon.png', // Icon Path
'menu_position' => 5

register_taxonomy( 'portfolio-tags', 'portfolio',
'hierarchical' => false,
'label' => __( 'Portfolio Tags' ),
'labels' => array(
'name' => __( 'Portfolio Tags' ),
'singular_name' => __( 'Portfolio Tag' )

add_action( 'init', 'custom_portfolio_posttype' );


Ashfame answers:

Yes! Default queries don't deal with custom post types.

For <em>Custom</em> post types, you need <em>Custom</em> queries ;)


Nilesh shiragave answers:

Yes for custom post types you need custom queries.

for more information you can check following articles

Great article for you as you are creating portfolio using custom post types

And for custom post types you can find all the links on this page


Monster Coder answers:

you can follow this link to get overall idea on custom post type

[[LINK href=""]]Here[[/LINK]]


Baki Goxhaj answers:

You do not need to worry - WordPress does what you require by default. You will need an extra argument on the query function to get the posts from your portfolio post type. Good luck!


juan manuel incaurgarat answers:

as said before, wordpress does it by it self, but remember that first, you have declare your new post types using something like this:

add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'acme_product',
'labels' => array(
'name' => __( 'Products' ),
'singular_name' => __( 'Product' )
'public' => true,

and then register ir with
<?php register_post_type( $post_type, $args ) ?>
(but remember not to use register_post_type before init

also take a look at this
this how you set the loop to use only one post type:
$loop = new WP_Query( array( 'post_type' => 'product', 'posts_per_page' => 10 ) );
while ( $loop->have_posts() ) : $loop->the_post();
echo '<div class="entry-content">';
echo '</div>';