• Resolved ARSGeek

    (@chambergeek)


    In my Custom Post Type, I’m not able to select a Primary Category like I can on the default WP Post edit screen. Is this something I need to activate in CPT UI? Any direction is appreciated.

    Screenshot: https://ibb.co/dtsPv5c

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    We don’t have any setting specific to that. That’s going to be all Yoast SEO functionality to handle.

    Last I knew, at least as long as it’s detecting the taxonomy, once you choose more than 1 term, it prompts you to specify the primary term.

    Thread Starter ARSGeek

    (@chambergeek)

    Hi Michael, Thank you for your reply. The Primary Category option is available if I am creating a default WordPress Post. But when I am creating an CPT UI Article, it is not available. Do you think that possibly Yoast is not recognizing the CPT custom article type?

    See screenshot below. The left is a standard WP Post, the right is a CPT UI Article. https://ibb.co/2K0yXyV

    Thread Starter ARSGeek

    (@chambergeek)

    Here is the Article Post Type code:

    function cptui_register_my_cpts_mark_category() {

    /**
     * Post Type: Articles.
     */
    
    $labels = [
        "name" => esc_html__( "Articles", "Avada" ),
        "singular_name" => esc_html__( "Article", "Avada" ),
    ];
    
    $args = [
        "label" => esc_html__( "Articles", "Avada" ),
        "labels" => $labels,
        "description" => "",
        "public" => true,
        "publicly_queryable" => true,
        "show_ui" => true,
        "show_in_rest" => true,
        "rest_base" => "",
        "rest_controller_class" => "WP_REST_Posts_Controller",
        "rest_namespace" => "wp/v2",
        "has_archive" => false,
        "show_in_menu" => true,
        "show_in_nav_menus" => true,
        "delete_with_user" => false,
        "exclude_from_search" => false,
        "capability_type" => "post",
        "map_meta_cap" => true,
        "hierarchical" => true,
        "can_export" => false,
        "rewrite" => [ "slug" => "article", "with_front" => true ],
        "query_var" => true,
        "supports" => [ "title", "editor", "thumbnail", "excerpt", "trackbacks", "comments", "revisions", "author", "page-attributes" ],
        "taxonomies" => [ "article-category" ],
        "show_in_graphql" => false,
    ];
    
    register_post_type( "mark_category", $args );

    }

    add_action( ‘init’, ‘cptui_register_my_cpts_mark_category’ );

    Thread Starter ARSGeek

    (@chambergeek)

    All Custom Post Type UI Taxonomies

    function cptui_register_my_taxes() {

    /**
     * Taxonomy: Article Categories.
     */
    
    $labels = [
        "name" => esc_html__( "Article Categories", "Avada" ),
        "singular_name" => esc_html__( "Article Category", "Avada" ),
    ];
    
    
    $args = [
        "label" => esc_html__( "Article Categories", "Avada" ),
        "labels" => $labels,
        "public" => true,
        "publicly_queryable" => true,
        "hierarchical" => false,
        "show_ui" => true,
        "show_in_menu" => true,
        "show_in_nav_menus" => true,
        "query_var" => true,
        "rewrite" => [ 'slug' => 'article-category', 'with_front' => true,  'hierarchical' => true, ],
        "show_admin_column" => false,
        "show_in_rest" => true,
        "show_tagcloud" => false,
        "rest_base" => "article-category",
        "rest_controller_class" => "WP_REST_Terms_Controller",
        "rest_namespace" => "wp/v2",
        "show_in_quick_edit" => false,
        "sort" => false,
        "show_in_graphql" => false,
    ];
    register_taxonomy( "article-category", [ "mark_category" ], $args );

    }
    add_action( ‘init’, ‘cptui_register_my_taxes’ );

    Thread Starter ARSGeek

    (@chambergeek)

    Article Categories Taxonomy

    function cptui_register_my_taxes_article_category() {

    /**
     * Taxonomy: Article Categories.
     */
    
    $labels = [
        "name" => esc_html__( "Article Categories", "Avada" ),
        "singular_name" => esc_html__( "Article Category", "Avada" ),
    ];
    
    
    $args = [
        "label" => esc_html__( "Article Categories", "Avada" ),
        "labels" => $labels,
        "public" => true,
        "publicly_queryable" => true,
        "hierarchical" => false,
        "show_ui" => true,
        "show_in_menu" => true,
        "show_in_nav_menus" => true,
        "query_var" => true,
        "rewrite" => [ 'slug' => 'article-category', 'with_front' => true,  'hierarchical' => true, ],
        "show_admin_column" => false,
        "show_in_rest" => true,
        "show_tagcloud" => false,
        "rest_base" => "article-category",
        "rest_controller_class" => "WP_REST_Terms_Controller",
        "rest_namespace" => "wp/v2",
        "show_in_quick_edit" => false,
        "sort" => false,
        "show_in_graphql" => false,
    ];
    register_taxonomy( "article-category", [ "mark_category" ], $args );

    }
    add_action( ‘init’, ‘cptui_register_my_taxes_article_category’ );

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Based on what I’m seeing, I think for “primary” term setting, you want the taxonomy to be registered as “hierarchical”

    Here I have 2 different custom taxonomies on a custom post type, and only “anthology” is hierarchical, and it gets the ‘primary” setting option

    Screen Shot

    Thread Starter ARSGeek

    (@chambergeek)

    Michael, Thank you. Setting the Taxonomy’s Hierarchical to “True” fixed it. Many Thanks!

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Welcome.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Setting Article Primary Category’ is closed to new replies.