Tagged: , ,

This topic contains 2 replies, has 2 voices, and was last updated by  cosmocanuck 4 years, 10 months ago.

  • Author
    Posts
  • #3064

    cosmocanuck
    Participant

    Hi guys. I created a couple of Custom Post Types, the Piklist way, but I have one (admittedly tiny) problem: the name of my CPT is displayed singularly in a couple of places where it really should be plural. Mainly, the URL slug, but also a breadcrumbs feature (which presumably is taking its info from the same place).

    My code was:

    add_filter('piklist_post_types', 'recipe_post_type');
    function recipe_post_type($post_types)
    {
    $post_types['recipe'] = array(
     	'labels' => piklist('post_type_labels', 'Recipes')
        ,'title' => __('Enter a new recipe title')
    	,'menu_icon' => 'dashicons-welcome-write-blog'
        ,'public' => true
        ,'taxonomies' => array('recipe_tags')
        ,'rewrite' => array('slug' => 'recipe')
        ,'supports' => array(
          'author'
          ,'title'
          ,'thumbnail'
          ,'revisions'
        	)
        ,'hide_meta_box' => array(
        	)
        );
    return $post_types;
    }
    

    And the URL is now

    http://www.website.com/category/recipe/some-recipe,

    when I’d prefer it to be

    http://www.website.com/category/recipes/some-recipe

    As well, my breadcrumbs display reads:

    Home / Recipe / Chili Con Carne

    I know the Piklist function uses all the parameters from the built-in WP function, but in studying the WP Codex, I’m still not sure where I went awry.

    I realize I may be up the creek now since I’ve already added lots of content to my CPT’s and this might mean some fancy database wrangling (or massive re-entry) to fix. But I thought I’d just mention it in case there’s some simple fix.

    Thanks!
    adam

  • #3066

    Steve
    Keymaster

    @cosmocanuck– I believe your are talking about two different things:

    1) URL Slug: This is set with this parameter, 'rewrite' => array('slug' => 'recipe'). However, you may want to read this article on Single vs Plural permalinks, before you change it.

    2) Breadcrumbs: I’m not 100% sure, but breadcrumbs may be generated from labels. You don’t have to use the Piklist function to generate the labels. You can manually set them up. Borrowing on the example in the codex:

    add_filter('piklist_post_types', 'recipe_post_type');
    function recipe_post_type($post_types)
    {
    
    $labels = array(
    	'name' => _x( 'Recipes', 'post type general name', 'your-plugin-textdomain' ),
    	'singular_name' => _x( 'Recipe', 'post type singular name', 'your-plugin-textdomain' ),
    	'menu_name' => _x( 'Recipes', 'admin menu', 'your-plugin-textdomain' ),
    	'name_admin_bar' => _x( 'Recipes', 'add new on admin bar', 'your-plugin-textdomain' ),
    	'add_new' => _x( 'Add New', 'book', 'your-plugin-textdomain' ),
    	'add_new_item' => __( 'Add New Recipe', 'your-plugin-textdomain' ),
    	'new_item' => __( 'New Recipe', 'your-plugin-textdomain' ),
    	'edit_item' => __( 'Edit Recipe', 'your-plugin-textdomain' ),
    	'view_item' => __( 'View Recipe', 'your-plugin-textdomain' ),
    	'all_items' => __( 'All Recipes', 'your-plugin-textdomain' ),
    	'search_items' => __( 'Search Recipes', 'your-plugin-textdomain' ),
    	'parent_item_colon' => __( 'Parent Recipes:', 'your-plugin-textdomain' ),
    	'not_found' => __( 'No Recipes found.', 'your-plugin-textdomain' ),
    	'not_found_in_trash' => __( 'No Recipes found in Trash.', 'your-plugin-textdomain' )
    );
    
    
    $post_types['recipe'] = array(
      'labels' => $labels
      ,'title' => __('Enter a new recipe title')
      ,'menu_icon' => 'dashicons-welcome-write-blog'
      ,'public' => true
      ,'taxonomies' => array('recipe_tags')
      ,'rewrite' => array('slug' => 'recipe')
      ,'supports' => array(
        'author'
        ,'title'
        ,'thumbnail'
        ,'revisions'
       )
     );
    return $post_types;
    }
    

    Let me know if this makes sense.

  • #3115

    cosmocanuck
    Participant

    Thanks a million Steve. Re: #2, I had sort of suspected there was a way for me to specify the various terms, but hadn’t grasped this concept enough to quite formulate the question! This does in fact make perfect sense and I have the plural now showing on both my Recipes and Products page breadcrumbs. Yay!

    As for changing the permalink, I see that it can be a tricky business, and frankly this is the less critical issue in my opinion, so I’m just going to leave it for now…

    Thanks again!

The topic ‘SIngular vs. plural name for Custom Post Type’ is closed to new replies.