Skip to content

Instantly share code, notes, and snippets.

@domantasg
Created September 22, 2017 09:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save domantasg/8e7634ac6166c6dcf2320ed00c72f9ea to your computer and use it in GitHub Desktop.
Save domantasg/8e7634ac6166c6dcf2320ed00c72f9ea to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: My Custom Post Types
Description: Add post types for movies and movie reviews
Author: Liam Carberry
*/
// Hook <strong>lc_custom_post_movie()</strong> to the init action hook
add_action( 'init', 'lc_custom_post_movie' );
// The custom function to register a movie post type
function lc_custom_post_movie() {
// Set the labels, this variable is used in the $args array
$labels = array(
'name' => __( 'Movies' ),
'singular_name' => __( 'Movie' ),
'add_new' => __( 'Add New Movie' ),
'add_new_item' => __( 'Add New Movie' ),
'edit_item' => __( 'Edit Movie' ),
'new_item' => __( 'New Movie' ),
'all_items' => __( 'All Movies' ),
'view_item' => __( 'View Movie' ),
'search_items' => __( 'Search Movies' ),
'featured_image' => 'Poster',
'set_featured_image' => 'Add Poster'
);
// The arguments for our post type, to be entered as parameter 2 of register_post_type()
$args = array(
'labels' => $labels,
'description' => 'Holds our movies and movie specific data',
'public' => true,
'menu_position' => 5,
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments', 'custom-fields' ),
'has_archive' => true,
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'has_archive' => true,
'query_var' => 'film'
);
// Call the actual WordPress function
// Parameter 1 is a name for the post type
// Parameter 2 is the $args array
register_post_type( 'movie', $args);
}
// Hook <strong>lc_custom_post_movie_reviews()</strong> to the init action hook
add_action( 'init', 'lc_custom_post_movie_reviews' );
// The custom function to register a movie review post type
function lc_custom_post_movie_reviews() {
// Set the labels, this variable is used in the $args array
$labels = array(
'name' => __( 'Movie Reviews' ),
'singular_name' => __( 'Movie Review' ),
'add_new' => __( 'Add New Movie Review' ),
'add_new_item' => __( 'Add New Movie Review' ),
'edit_item' => __( 'Edit Movie Review' ),
'new_item' => __( 'New Movie Review' ),
'all_items' => __( 'All Movie Reviews' ),
'view_item' => __( 'View Movie Reviews' ),
'search_items' => __( 'Search Movie Reviews' )
);
// The arguments for our post type, to be entered as parameter 2 of register_post_type()
$args = array(
'labels' => $labels,
'description' => 'Holds our movie reviews',
'public' => true,
'menu_position' => 6,
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments', 'custom-fields' ),
'has_archive' => true,
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'has_archive' => true
);
// Call the actual WordPress function
// Parameter 1 is a name for the post type
// $args array goes in parameter 2.
register_post_type( 'review', $args);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment