Support » Plugin: Custom Post Type UI » Categories of a cpt not working

  • Resolved bort5

    (@bort5)


    Hello everybody,

    I have created a ctp called “interventions” . It should support 7 categories. No problems with the general archive of “Interventions” but when I try to use its categories they don’ t work.I put both the archive and all the categories displayed on the front-endmenu. The mistake found is that it doesn’t find the page when I click on the front-end menu voice.

    This is the code I added on functions.php

    /*—————————————————————————————*/
    add_action( ‘init’, ‘register_my_cpts_interventions’ );
    function register_my_cpts_interventions() {
    $interv_labels = array(
    “name” => __( ‘interventions’, ‘rookie’ ),
    “singular_name” => __( ‘intervention’, ‘rookie’ ),
    “menu_name” => __( ‘interventions active’, ‘rookie’ ),
    “all_items” => __( ‘Tutte le interventions’, ‘rookie’ ),
    ‘edit_item’ => __( ‘Edit intervention’ ),
    “archives” => __( ‘interventions’, ‘rookie’ ),
    );

    $args = array(
    “label” => __( ‘interventions’, ‘rookie’ ),
    “labels” => $interv_labels,
    “description” => “”,
    “public” => true,
    “publicly_queryable” => true,
    “show_ui” => true,
    “show_in_rest” => false,
    “rest_base” => “interventions”,
    “has_archive” => true,
    “show_in_menu” => true,
    “exclude_from_search” => true,
    “capability_type” => “post”,
    “map_meta_cap” => true,
    “hierarchical” => true,
    “rewrite” => array( “slug” => “interventions”, “with_front” => true ),
    “query_var” => “interventions”, //”intervention” è sbagliata !!!
    “menu_icon” => “dashicons-megaphone”,
    “supports” => array( “title”, “editor”, “interventions categories” ),
    “taxonomies” => array( “interventions” ),
    );
    register_post_type( “interventions”, $args );

    }

    // End of register_my_cpts_interventions()

    add_action( ‘init’, ‘register_my_taxonomies_interventions’ );
    function register_my_taxonomies_interventions() {
    $labels_taxo_interv = array(
    “name” => __( ‘interventions categorie’, ‘rookie’ ),
    “singular_name” => __( ‘category intervention’, ‘rookie’ ),
    );

    $args = array(
    “label” => __( ‘interventions categories’, ‘rookie’ ),
    “labels” => $labels_taxo_interv,
    “public” => true,
    “hierarchical” => true,
    “label” => “interventions categories”,
    “show_ui” => true,
    “show_in_menu” => true,
    “show_in_nav_menus” => true,
    “query_var” => ‘interventions’,//true,
    “rewrite” => array( ‘slug’ => ‘interventions categories’, ‘with_front’ => true, ‘hierarchical’ => true, ),
    “show_admin_column” => false,
    “show_in_rest” => false,
    “rest_base” => “”,
    “show_in_quick_edit” => false,
    );
    register_taxonomy( “interventions”, array( “interventions” ), $args );

    // End register_my_taxes_interventions()
    }

    /*———————————————————————————-*/

    I added also this function , as signaled on your FAQ section of the plugin

    function add_custom_types_to_tax( $query ) {
    if( is_category() || is_tag() && empty( $query->query_vars[‘suppress_filters’] ) ) {

    // Get all your post types
    $post_types = array( ‘post’, ‘interventions’ );

    $query->set( ‘interventions’, $post_types );
    return $query;
    }
    }
    add_filter( ‘pre_get_posts’, ‘add_custom_types_to_tax’ );

    /*———***********************************************************************/

    and I tried to install your plugin of course. I don’t know what I’m doing wrong. Could somebody give me a hand ?

    Thanks in advance

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Michael Beckwith

    (@tw2113)

    The BenchPresser

    Not quite following what the actual issue is. You’re seeing a 404 when you visit the permalink to something? Either the single post, or perhaps the taxonomy term link archive? Something else?

    I see the post ( with category) and I see the taxonomy but it ‘s shown empty.In other words it doesn’t link the post to its category

    BTW, I’m not sure: do I have to create a taxonomy-interventions.php and a category-interventions.php ?

    Plugin Author Michael Beckwith

    (@tw2113)

    The BenchPresser

    Is the spot in question publicly accessible anywhere? I’m a bit curious.

    No, you don’t NEED to create those template files. Both of these should fall back to archives.php if a more specific template isn’t available. In the case of a category, it’d hit category.php first before archive.php.

    Plugin Author Michael Beckwith

    (@tw2113)

    The BenchPresser

    Any changes or updates with this one @bort5?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Categories of a cpt not working’ is closed to new replies.