Post Types « WordPress Codex - 1 views
codex.wordpress.org/Post_Types
wordpress custom post types database content best practices namespace templates function reference CMS custom post types
shared by Vernon Fowler on 22 Mar 13
- No Cached
-
it is better if you prefix your identifier with a short namespace that identifies your plugin, theme or website that implements the custom post type. For example: acme_product or aw_product for products post type used by a hypothetical ACMEWidgets.com website
-
Namespacing your custom post type identifier will not guarantee against conflicts but will certainly minimize their likelihood.
-
Do pay close attention to not having your custom post type identifier exceed 20 characters though, as the post_type column in the database is currently a VARCHAR field of that length.
- ...6 more annotations...
-
register_post_type( 'acme_product', array( 'labels' => array( 'name' => __( 'Products' ), 'singular_name' => __( 'Product' ) ), 'public' => true, 'has_archive' => true, ) );
-
When you namespace a custom post type identifier and still want to use a clean URL structure, you need to set the rewrite argument of the register_post_type() function. For example, assuming the ACME Widgets example from above:
-
Note: In some cases, the permalink structure must be updated in order for the new template files to be accessed when viewing posts of a custom post type.
-
single posts of a custom post type will use single-{post_type}.php and their archives will use archive-{post_type}.php where {post_type} is the $post_type argument of the register_post_type() function.
-
In any template file of the WordPress theme system, you can also create new queries to display posts from a specific post type. This is done via the post_type argument of the WP_Query object.