Site logo

Archived topic

Block element for custom post type

8 replies · Started by Helene on February 28, 2022

Viewing posts 1–9 of 9

Hello,

I have problem with a block Elements for a custom post type.
The display works fine for the Archive page but not for the category.
Exemple for the Archive : http://family-roadtrip.com/loisirs/
Click on the taxonomy (Visistes or Plages) and i want to have the same thing...
I hope you understand me because i'm french !

block element parameters

thank you for your help

Helene

Hi there,

can you check the ID and password you provided ? As it is not working for me.

Sorry, can you try again with the id bellow

I created taxonomy instead of activate category... and when i click en this type of loisir... boum... aïe... nothing
I have modify the block element but i don't know what i can do more... maybe something to add in functions.php ?

thank you

How did you create the Custom Post Type and Custom Taxonomy ?

in the functions.php


// # custom post type
add_action('init', 'loisir_post_type');

function loisir_post_type()
{
    // custom post type name is 20 maximum.
    register_post_type(
    'chg_loisir_cpt',
    array(
        'labels' => array(
        'name' => __('Loisirs', 'chahogi'),
        'singular_name' => __('Loisir', 'chahogi'),
        'add_new' => __('Ajouter un loisir', 'chahogi'),
        'add_new_item' => __('Ajouter un loisir', 'chahogi'),
        'edit' => __('Modifier', 'chahogi'),
        'edit_item' => __('Modifier Loisir', 'chahogi'),
        'new_item' => __('Nouveau Loisir', 'chahogi'),
        'view' => __('Voir', 'chahogi'),
        'view_item' => __('Voir le Loisir', 'chahogi'),
        'search_items' => __('Recherche Loisir', 'chahogi'),
        'not_found' => __('Aucun loisir trouvé', 'chahogi'),
        'not_found_in_trash' => __('Aucun loisir trouvé', 'chahogi'),
		
        ),
        'public' => true,
        'show_ui' => true,
	'query_var' => true,
        'menu_position' => 5,
        'supports' => array('title', 'editor', 'thumbnail'),
        'rewrite' => array('slug' => __('loisirs', 'chahogi')),
        'has_archive' => true,
		'show_in_rest'  => true,		//add Gutenberg compatibility
		'show_in_menu'  => true,
		'hierarchical'          => false,
		'public'                => true,
		'show_in_admin_bar'     => true,
		'show_in_nav_menus'     => true,
		'can_export'            => true,
		'exclude_from_search'   => false,
		'publicly_queryable'    => true,
        'menu_icon' => 'dashicons-location-alt'
    )
    );
}

/** Création d'une taxonomie spécifique pour les loisirs ***/
function loisirs_taxonomies() {
    // Add new taxonomy, make it hierarchical (like categories)
    $labels = array(
        'name'              => _x( 'Types', 'taxonomy general name', 'chahogi' ),
        'singular_name'     => _x( 'Type', 'taxonomy singular name', 'chahogi' ),
        'search_items'      => __( 'Recherche Type', 'chahogi' ),
        'all_items'         => __( 'Tous les types', 'chahogi' ),
        'parent_item'       => __( 'Parent Type', 'chahogi' ),
        'parent_item_colon' => __( 'Parent Type:', 'chahogi' ),
        'edit_item'         => __( 'Edit Type', 'chahogi' ),
        'update_item'       => __( 'Update Type', 'chahogi' ),
        'add_new_item'      => __( 'Add New Type', 'chahogi' ),
        'new_item_name'     => __( 'New Type Name', 'chahogi' ),
        'menu_name'         => __( 'Type de loisir', 'chahogi' ),
    );
 
    $args = array(
        'hierarchical'      => true,
        'labels'            => $labels,
        'show_ui'           => true,
        'show_admin_column' => true,
        'query_var'         => true,
	'has_archive' 		=> true,
	'show_in_rest'  	=> true,		//add Gutenberg compatibility
        'rewrite'           => array( 'slug' => 'genre' ),
    );
 
    register_taxonomy( 'genre', array( 'chg_loisir_cpt' ), $args );
 
}
// hook into the init action and call create_book_taxonomies when it fires
add_action( 'init', 'loisirs_taxonomies', 0 );

Sometimes using the rewrite option in register_post_type can cause this issue.

Can you try saving your Permalinks in "Settings > Permalinks"? Sometimes that fixes it.

Let us know :)

The problem came from the category prefixes in the permalinks. I removed the custom prefix and it works normally now.
Thank you for your help.

Have a nice day
Helene

Glad you got it sorted :)

This archived topic is closed to new replies.