Tutorial by Examples

Say you have a library website, and you want to have a custom post type named Books. It can be registered as function create_bookposttype() { $args = array( 'public' => true, 'labels' => array( 'name' => __( 'Books' ), 'singular_name' => ...
Registering a custom post type does not mean it gets added to the main query automatically. You need to use pre_get_posts filter to add custom post types to main query. // Show posts of 'post' and 'book' custom post types on home page add_action( 'pre_get_posts', 'add_my_post_types_to_query' ); ...
Registering a custom post type does not mean it gets added to the main RSS feed automatically.You need to use request filter to add custom post types to main RSS feed. // Add 'books' custom post types on main RSS feed function add_book_post_types_to_rss($qv) { if (isset($qv['feed']) &&amp...
if ( ! function_exists('products_post_type') ) { function products_post_type() { $labels = array( 'name' => _x( 'Products', 'Post Type General Name', 'text_domain' ), 'singular_name' => _x( 'Product', 'Post Type Singular Name', 'text_domain'...
You can use any name for the function. function custom_postype(){ register_post_type('cus_post',array( 'labels'=>array( 'name'=>'khaiyam'// Use any name you want to show in menu for your users ), 'public'=>true,// **Must required ...
You can add custom post type posts on default wordpress search, Add below code in theme functions.php function my_search_filter($query) { if ( !is_admin() && $query->is_main_query() ) { if ($query->is_search) { $query->set('post_type', array( 'news','post','article' ...

Page 1 of 1