-
-
Save farnscosnippet/7328126 to your computer and use it in GitHub Desktop.
WORDPRESS - Register Custom Post Type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Registering Custom Post Type for Replace_names | |
function custom_type_Replace_names() { | |
$labels = array( | |
'name' => 'Replace_names', | |
'singular_name' => 'Replace_name', | |
'add_new' => 'Add Replace_name', | |
'add_new_item' => 'Add New', | |
'edit_item' => 'Edit Replace_name', | |
'new_item' => 'New Replace_name', | |
'all_items' => 'All Replace_names', | |
'view_item' => 'View Replace_name', | |
'search_items' => 'Search Replace_names', | |
'not_found' => 'Nope, nothing here.', | |
'not_found_in_trash' => 'The trash is empty, no need to go dumpster-diving.', | |
'parent_item_colon' => '', | |
'menu_name' => 'Replace_names' | |
); | |
$args = array( | |
'labels' => $labels, | |
'public' => true, | |
'taxonomies' => array( 'category', 'post_tag' ), | |
'publicly_queryable' => true, | |
'show_ui' => true, | |
'show_in_menu' => true, | |
'query_var' => true, | |
'rewrite' => array( 'slug' => 'Replace_names' ), | |
'capability_type' => 'page', | |
'has_archive' => true, | |
'hierarchical' => false, | |
'menu_position' => 6, // 5 - below Posts, 10 - below Media, 15 - below Links, 20 - below Pages, 25 - below comments, 60 - below first separator, 65 - below Plugins, 70 - below Users, 75 - below Tools, 80 - below Settings, 100 - below second separator | |
'menu_icon' => get_stylesheet_directory_uri() . '/img/ico-h.png', // OPTIONAL | |
'supports' => array( 'title', 'editor', 'thumbnail') | |
); | |
register_post_type( 'Replace_names', $args ); | |
} | |
add_action( 'init', 'custom_type_Replace_names' ); | |
// Adding custom messaging for Replace_names | |
function custom_type_Replace_names_updated_messages( $messages ) { | |
global $post, $post_ID; | |
$messages['custom_type_Replace_names'] = array( | |
0 => '', // Unused. Messages start at index 1. | |
1 => sprintf( __('Replace_name updated. <a href="%s">View Replace_name</a>', 'your_text_domain'), esc_url( get_permalink($post_ID) ) ), | |
2 => __('Replace_name updated.', 'your_text_domain'), | |
3 => __('Replace_name deleted.', 'your_text_domain'), | |
4 => __('Replace_name updated.', 'your_text_domain'), | |
/* translators: %s: date and time of the revision */ | |
5 => isset($_GET['revision']) ? sprintf( __('Replace_name restored to revision from %s', 'your_text_domain'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, | |
6 => sprintf( __('Replace_name published. <a href="%s">View Replace_name</a>', 'your_text_domain'), esc_url( get_permalink($post_ID) ) ), | |
7 => __('Replace_name saved.', 'your_text_domain'), | |
8 => sprintf( __('Replace_name submitted. <a target="_blank" href="%s">Preview Replace_name</a>', 'your_text_domain'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ), | |
9 => sprintf( __('Replace_name scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview Replace_name</a>', 'your_text_domain'), | |
// translators: Publish box date format, see http://php.net/date | |
date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ), | |
10 => sprintf( __('Replace_name draft updated. <a target="_blank" href="%s">Preview Replace_name</a>', 'your_text_domain'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ), | |
); | |
return $messages; | |
} | |
add_filter( 'post_updated_messages', 'custom_type_Replace_names_updated_messages' ); | |
// Adding Replace_names to Tags and Categories | |
function add_custom_types_to_tax( $query ) { | |
if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) { | |
// Get all your post types | |
$post_types = get_post_types(); | |
$query->set( 'post_type', $post_types ); | |
return $query; | |
} | |
} | |
add_filter( 'pre_get_posts', 'add_custom_types_to_tax' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment