WordPress Post Type Function
In Previous article we discussed about wordpress plugin creation, for more info please follow below links for wordpress plugin development.
- https://www.eknowledgetree.com/wordpress/wordpress-plugin-development-from-scratch-lesion-1/
- https://www.eknowledgetree.com/wordpress/wordpress-plugin-development-from-scratch-lesion-1/
In this session we discuss about wordpress register post type function, which we can use this function in plugins and themes, before that we need to know this register_post_type() will only invoked ‘init’ action. This will not work if we call this function before init action.
WordPress uses following post types already, there are..
post
page
attachment
revision
nav_menu_item
Some of the post types should not use, because they interfere with other WordPress functions, there are…
action
author
order
theme
Now we will create a sample register_post_type() example as below.
<?php /* Plugin Name: joseph gallery Description: joseph Gallery Application Version: 0.1 Author: joseph reddy Author URI: http://wwww.eknowledgetree.com */ if(!defined('ABSPATH'))exit; if(!defined('WP_CONTENT_URL')) { define ('WP_CONTENT_URL',get_option('site_url').'/wp-content'); } if (!defined( 'WP_CONTENT_DIR' ) ) { define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' ); } if (!defined( 'WP_PLUGIN_URL' ) ) { define( 'WP_PLUGIN_URL', WP_CONTENT_URL. '/plugins' ); } if (!defined( 'WP_PLUGIN_DIR' ) ) { define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' ); } function register_joseph_gallery() { $labels = array( 'name' => _x( 'Photos', 'Photos_gallery' ), 'singular_name' => _x( 'Photos', 'Photos_gallery' ), 'add_new' => _x( 'Add New', 'Photos_gallery' ), 'add_new_item' => _x( 'Add New photos', 'Photos_gallery' ), 'edit_item' => _x( 'Edit photos Gallery', 'Photos_gallery' ), 'new_item' => _x( 'New photos Gallery', 'Photos_gallery' ), 'view_item' => _x( 'View photos Gallery', 'Photos_gallery' ), 'search_items' => _x( 'Search photos Gallery', 'Photos_gallery' ), 'not_found' => _x( 'No photos found', 'Photos_gallery' ), 'not_found_in_trash' => _x( 'No photos found in Trash', 'Photos_gallery' ), 'menu_name' => _x( 'photos', 'Photos_gallery' ), ); $args = array( 'labels' => $labels, 'hierarchical' => true, 'description' => 'Photos', 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'trackbacks', 'comments', 'revisions','tags', 'page-attributes' ), 'taxonomies' => array( 'genres' ), 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'menu_position' => 10, 'menu_icon' => 'dashicons-playlist-video', 'show_in_nav_menus' => true, 'publicly_queryable' => true, 'exclude_from_search' => false, 'has_archive' => true, 'query_var' => true, 'can_export' => true, 'rewrite' => true, 'capability_type' => 'post' ); register_post_type( 'joseph_gallery', $args ); } add_action( 'init', 'register_joseph_gallery' ); ?>
For more information you can go to below link as reference Post type function. Thanks.
Thank you for giving the information. It will help me lot.
Saved as a favorite, I actually like your site!