Blog

How to Register custom post with taxonomy in wordpress

WordPress comes with Default Post called Posts and two taxonomies called categories and tags. You can use them to organize your blog posts.

If you want to create New post in your site then WordPress gives the option to create a custom post and a custom post type.

For instance, you can create a custom post type called ‘Recipe’ and sort it using a custom taxonomy called ‘Recipe Type’.

You can add Recipe Type terms like Breakfast, Lunch, Dinner,snacks etc. This would allow you, and your site readers to easily sort Recipes by each Type.

Now, Let’s learn how to create custom post with taxonomies in WordPress.

Step 1 : Register Custom Post in Function.php File

Open your function.php file from the theme and add the following code to register the custom post.


add_action ('init', 'create_post_type');
function create_post_type() {
  register_post_type( 'recipe',
  	array(
  		'labels' => array(
  			'name' => __( 'Recipe' ),
  			'singular_name' => __( 'Recipe' )
  		),
			'menu_icon'           => 'dashicons-cart',
  		'public' => true,
  		'has_archive' => false,
  		'rewrite' => array('slug' => 'recipe'),
			'taxonomies' => array('post_tag'),
			'supports' => array('title','editor','thumbnail','tag')
  	)
  );

  register_taxonomy('recipe_types',array('recipe'),
  	array(
  		'labels' => array(
  			'name' => __('Recipe Types'),
  			'singular_name' => __('Recipe Type')
  		),
  		'hierarchical'      => true,
  		'show_ui'           => true,
  		'show_admin_column' => true,
  		'query_var'         => true,
  		'rewrite'           => array( 'slug' => 'recipe_type' ),
  		'supports' => array('title')
  	)

  );
}

Above code will create a new section in admin called Recipe which we call Custom Post Type.
And Recipe type, which we call Custom post taxonomy .

Now, you can Add Recipes with Their Types and show in your site.

Apart from this, business demands are rising everyday and loads of data is being transferred. We help in creating a custom, dynamic, robust, scalable and secure system that will reduce the operational cost and increase productivity. Hire WordPress developers who can make tailor-made wordpress enterprise applications to create unique and engaging solutions.

For more details, talk to our WordPress Experts now.

Lets Nurture

Share
Published by
Lets Nurture

Recent Posts

Q/A System — Deep learning (1/2)

Deep Learning is a subfield of machine learning concerned with algorithms inspired by the structure…

2 days ago

Q/A System — Deep learning(2/2)

How LSTM works? I think it’s unfair to say that neural network has no memory…

3 days ago

Image classification Api — deep learning

What is Deep Learning? Deep Learning is a new area of Machine Learning research, which…

3 days ago

What is Generative AI?

Generative AI refers to a category of advanced algorithms designed to produce original content across…

3 weeks ago

5 Generative AI Video Tools Everyone Should Know About

Generative AI Video Tools Everyone Should Know About Generative AI is revolutionizing video creation, making…

3 weeks ago

What Exactly Are LLMs (Large Language Models)?

Large Language Models (LLMs)  are a transformative advancement in artificial intelligence, capable of understanding, processing,…

3 weeks ago