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

WP3 Post Type Question WordPress

  • SOLVED

For my new theme @ [[LINK href="http://blackops.turkhitbox.com/"]]http://blackops.turkhitbox.com/[[/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)

2010-08-24

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',
array(
'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',
array(
'hierarchical' => false,
'label' => __( 'Portfolio Tags' ),
'labels' => array(
'name' => __( 'Portfolio Tags' ),
'singular_name' => __( 'Portfolio Tag' )
)
)
);
}

add_action( 'init', 'custom_portfolio_posttype' );

2010-08-24

Ashfame answers:

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

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

2010-08-24

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

http://www.vooshthemes.com/blog/wordpress-tip/create-a-professional-portfolio-using-wordpress-3-0-custom-post-types/


And for custom post types you can find all the links on this page
http://www.snilesh.com/resources/wordpress/wordpress-custom-post-types-and-taxonomies/

2010-08-24

Monster Coder answers:

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

[[LINK href="http://kovshenin.com/archives/custom-post-types-in-wordpress-3-0/"]]Here[[/LINK]]

2010-08-24

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!

2010-08-25

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',
array(
'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();
the_title();
echo '<div class="entry-content">';
the_content();
echo '</div>';
endwhile;