Tagged: Custom Post Type, custom taxonomy
-
AuthorPosts
-
October 9, 2019 at 11:46 am #1146477
Dear support team,
as suggested from Ismael here, I open a new thread to find a solution to my problem.
After creating a new Custom Post Type named ‘FAQ’ I made and associate to it a Custom Taxonomy named ‘Categorie FAQ’.
I made them in the function.php file of the child theme whitch is the active theme.Unfortunatelly I’m workin on a private server so I can’t share temporary access credentials.
Here is the code i used to create the CPT:
function cd_custom_post() { register_post_type( 'faq', array('labels' => array( 'name' => 'FAQ', 'singular_name' => 'FAQ', 'all_items' => 'Tutte le FAQ', 'add_new' => 'Aggiungi nuova', 'add_new_item' => 'Aggiungi nuova FAQ', 'edit_item' => 'Modifica FAQ', 'new_item' => 'Nuova FAQ', 'view_item' => 'Visualizza FAQ', 'search_items' => 'Cerca FAQ', 'not_found' => 'Nessuna FAQ trovata', 'not_found_in_trash' => 'Nessun FAQ trovata nel cestino', 'parent_item_colon' => '' ), 'description' => 'Raccolta delle FAQ del portale', 'public' => true, 'publicly_queryable' => true, 'exclude_from_search' => false, 'show_ui' => true, 'query_var' => true, 'show_in_menu' => true, 'show_in_nav_menus' => true, 'menu_position' => 6, 'menu_icon' => 'dashicons-editor-spellcheck', 'rewrite' => array( 'slug' => 'faq', 'with_front' => true ), 'has_archive' => false, 'capability_type' => 'page', 'hierarchical' => true, 'taxonomies' => array('Categoria FAQ'), 'supports' => array( 'title', 'editor', 'trackbacks', 'custom-fields', 'revisions', 'sticky', 'custom-fields',) ) ); } add_action( 'init', 'cd_custom_post');
And this is the code I used to create the Custom Taxonomy associated:
add_action( 'init', 'crea_tassonomia_categoria_faq', 0 ); function crea_tassonomia_categoria_faq() { $labels = array( 'name' => _x( 'Categorie FAQ', 'taxonomy general name' ), 'singular_name' => _x( 'Categoria FAQ', 'taxonomy singular name' ), 'search_items' => __( 'Cerca per categoria FAQ' ), 'all_items' => __( 'Tutte le FAQ' ), 'parent_item' => __( 'Categoria Principale' ), 'parent_item_colon' => __( 'Categoria Principale:' ), 'edit_item' => __( 'Modifica Categoria FAQ' ), 'update_item' => __( 'Aggiorna Categoria FAQ' ), 'add_new_item' => __( 'Aggiungi Nuova Categoria FAQ' ), 'new_item_name' => __( 'Nome Nuova Categoria FAQ' ), 'menu_name' => __( 'Categoria FAQ' ), ); register_taxonomy('Categoria FAQ',array('FAQ'), array( 'hierarchical' => true, 'labels' => $labels, 'show_ui' => true, 'show_admin_column' => true, 'query_var' => true, 'rewrite' => array( 'slug' => 'categoria-faq' ), )); }
As I mentioned in the previous thread, when I want to show a masonry grid filtered by taxonomy, if I use the “filter by taxonomy” funcionality to select posts to show, it gives me back the taxonomies list I’ve used to categoraize my blog posts img.
But when i do the same with Custom taxonomy i made before, it doesn’t populate any list of voices imgThere is any way to solve this problem?
Thanks in advance for your help!- This topic was modified 5 years, 1 month ago by maiscom.
October 14, 2019 at 5:48 am #1147715Hey maiscom,
Sorry for the delay. In the screenshot, there is another list of entries above the taxonomy dropdown. Did you enable the custom post type support selection?
This line is invalid:
register_taxonomy('Categoria FAQ',array('FAQ'), array(
You have to use the actual name of the custom post type “faq”, and the taxonomy name should not contain spaces and capital letters.
register_taxonomy('categoria-faq',array('faq'), array(
// https://codex.wordpress.org/Function_Reference/register_taxonomy
// https://codex.wordpress.org/Function_Reference/register_post_typeParameters:
$post_type
(string) (required) Post type. (max. 20 characters, cannot contain capital letters, underscores or spaces)
Default: None$taxonomy
(string) (required) The name of the taxonomy. Name should only contain lowercase letters and the underscore character, and not be more than 32 characters long (database structure restriction). Default: NoneBest regards,
IsmaelOctober 14, 2019 at 10:10 am #1147770Thanks Ismael. You solved the problem!
My fault was to use capital letter and spaces on CT registration.- This reply was modified 5 years, 1 month ago by maiscom.
October 15, 2019 at 5:35 am #1147945 -
AuthorPosts
- You must be logged in to reply to this topic.