• Hi! I am new to theme development, and I want to do all without plugins. (unless I create them that is). I have learned about custom post types and taxonomy, but I cannot get it to work like it does in the video. There are actually a couple of problems, but first one first and we’ll see if that fixes the rest.

    There is a custom post type called Recipes. Then the category is supposed to be Country. User makes a recipe post (which will eventually have its own html template) and gets to select which country categor y it will go to. I see in the video that the category goes below custom post type in admin bar, but for me, it does not. Can anyone tell me what I am doing wrong? Thanks!

    
    <code>
    // Register Taxonomy Country
    function create_country_tax() {
    
    	$labels = array(
    		'name'              => _x( 'Countries', 'taxonomy general name', 'textdomain' ),
    		'singular_name'     => _x( 'Country', 'taxonomy singular name', 'textdomain' ),
    		'parent_item'       => __( 'Recipes' ),
    
    	);
      $args = array(
      'labels' => $labels,
      'description' => __( '', 'textdomain' ),
      'hierarchical' => true,
      'public' => true,
      'publicly_queryable' => true,
      'show_ui' => true,
      'show_in_menu' => true,
      'show_in_nav_menus' => true,
      'show_tagcloud' => false,
      'show_in_quick_edit' => true,
      'show_admin_column' => true,
      'show_in_rest' => true,
      'taxonomies' => array('Countries'),
    );
    	register_taxonomy( 'country', array('Recipes'), $args );
    
    }
    add_action( 'init', 'create_country_tax' );
    
    
Viewing 1 replies (of 1 total)
  • Hi @darktranquilitynyc
    It looks like you are trying to create a custom taxonomy called “Country” for your “Recipes” custom post type.

    There are a few things you can try to troubleshoot the issue:

    1. Make sure you have registered the “Recipes” custom post type before registering the “Country” taxonomy. The order in which you register custom post types and taxonomies matters and the custom post type should be registered before the taxonomy.

    2. In the $args array for the taxonomy, try setting ‘hierarchical’ to true instead of false. This will make the taxonomy behave like a category, allowing you to select it from the post editor screen in the WordPress admin.

    3. Make sure you have the correct spelling and capitalization for the taxonomy name and labels. For example, in the $labels array, the taxonomy is referred to as “Country”, but in the $args array, it is referred to as “Countries”. It’s essential to be consistent with the spelling and capitalization of the taxonomy name.

    4. In the $labels array, the ‘parent_item’ label should have a value that is the name of the taxonomy, not the custom post type. In this case, it should be ‘Country’ instead of ‘Recipes’.

    5. In the $args array, the ‘taxonomies’ argument should be an array of taxonomy names, not a string. In this case, it should be array(‘country’) instead of array(‘Countries’).

    I hope this helps! Let me know if you have any other questions or if you need further assistance.

Viewing 1 replies (of 1 total)

The topic ‘Custom post type and taxonomy problem’ is closed to new replies.