Wordpress - Create Custom Post Type

add_action( 'init', 'create_listings' ); function create_listings() { $labels = array( 'name' => _x('Listings', 'post type general name'), 'singular_name' => _x('Listing', 'post type singular name'), 'add_new' => _x('Add New', 'Listing'), 'add_new_item' => __('Add New Lisiting'), 'edit_item' => __('Edit Listing'), 'new_item' => __('New Listing'), 'view_item' => __('View Listing'), 'search_items' => __('Search Listings'), 'not_found' => __('No Listings found'), 'not_found_in_trash' => __('No Listings found in Trash'), 'parent_item_colon' => '' ); $supports = array('title', 'editor', 'custom-fields', 'revisions', 'excerpt'); register_post_type( 'Listing', array( 'labels' => $labels, 'public' => true, 'supports' => $supports ) ); } //** Use this snippet within a page template, before the loop, to call the post type <?php query_posts(array('post_type'=>'listing')); ?>
T his code creates a custom post type for generic 'listings'. You'll next need to create or edit a page template to use the snippet.

Use the second code snippet right before the beginning of the WordPress Loop to call the 'listings' posts.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.