• Dear Supporters,

    its already hard to explain my problem in german ;(

    i have a cpt “machine” with several machine-types. (taxonomy)

    i want to add tags and refer them to the special machines.

    some of the machines of certain machine type have the same tag (tag name) but different tag (tag slug)

    ex: 2 machines are floor machines (tag name = floor) but the slugs are different: one floor-machine has the slug floor-linear and the other floor-radial

    when i want to add a tag to a linear-floor-machine in the backend i get a list: floor,floor in the tag dropdown field.

    How can i change the given list from displaying the tag names to tag slug.

    Is there a filter ?

    please help

    thx muki

Viewing 3 replies - 1 through 3 (of 3 total)
  • I have a couple of questions:

    1) Which editor is your CPT using?

    If it’s the block editor, I’m not sure that you can filter that and may need to code a custom editor component. If it’s the classic editor, there may be a filter hook.

    2) If your CPT uses the classic editor, is the machine-types taxonomy hierarchical or non-hierarchical?

    Thread Starter mukethedude

    (@mukethedude)

    thx for the fast answer:

    1.) classic

    2.) the taxonomies of the machines are hierarchical?. but my question belongs to the non-hierarchical tags. standard tags of all posts

    extract of functions.php:

    // Maschine - Machine
    
    add_action('init', 'add_ruff_machine');
    
    function add_ruff_machine() {
    
        $labels = array(
    
                'name' => _x('Machines', 'post type general name','ruff-gmbh'),
    
                'singular_name' => _x('Machine', 'post type singular name','ruff-gmbh'),
    
                'add_new' => __('Add machine','ruff-gmbh'),
    
                'all_items' => __('All machines','ruff-gmbh'),
    
                'add_new_item' => __('New machine','ruff-gmbh'),
    
                'edit_item' => __('Change machine','ruff-gmbh'),
    
                'new_item' => __('New machine','ruff-gmbh'),
    
                'view_item' => __('Show machine','ruff-gmbh'),
    
                'search_items' => __('Search for machine','ruff-gmbh'),
    
                'not_found' => __('No machine found','ruff-gmbh'),
    
                'not_found_in_trash' => __('No machine in trash','ruff-gmbh'),
    
                'parent_item_colon' => ''
    
        );
    
        $supports = array('title','thumbnail','editor','custom-fields');
    
        $args = array(
    
            'labels' => $labels,
    
            'public' => true,
    
            'publicly_queryable' => true,
    
            'show_ui' => true,
    
            '_builtin' => false,
    
            'show_in_menu' => true,
    
            'show_in_nav_menus' => true,
    
            'query_var' => true,
    
            'rewrite' => array('slug' => 'machine'),
    
            'capability_type' => 'post',
    
            'hierarchical' => false,
    
            'has_archive' => true,
    
            'menu_position' => 10,
    
            'menu_icon' => 'dashicons-admin-generic',
    
            'taxonomies' => array('post_tag'),//'category'),
    
            'supports' => $supports
    
        );
    
        register_post_type('machine',$args);
    
    }
    //  
    
        // CPT-Kategorie: Maschinentyp
    
        //
    
          $labels = array(
    
            'name' => _x('Machine type', 'general name' ),
    
            'singular_name' => _x('Machine type', 'taxonomy singular name' ,'ruff-gmbh'),
    
            'search_items' =>  __('Search for machine type','ruff-gmbh'),
    
            'all_items' => __('All machine types','ruff-gmbh'),
    
            'edit_item' => __('Change machine type','ruff-gmbh'),
    
            'update_item' => __('Update machine type','ruff-gmbh'),
    
            'add_new_item' => __('Add new machine type','ruff-gmbh'),
    
            'new_item_name' => __('New machine type name','ruff-gmbh'),
    
            'menu_name' => __('Machine type','ruff-gmbh'),
    
          );    
    
          register_taxonomy('machine-type',array('machine'), array(
    
            'hierarchical' => true,
    
            'labels' => $labels,
    
            'show_ui' => true,
    
            'show_in_rest' => true,
    
            'show_admin_column' => true,
    
            'query_var' => true,
    
            'rewrite' => array( 'slug' => 'machine-type' ),
    
          ));
    Moderator bcworkz

    (@bcworkz)

    If you see a checkbox list for your terms, altering the displayed names by filter is difficult because only the name is passed for context. You likely will need to develop you own meta box callback. You can use the source code for wp_terms_checklist() as a starting point.

    Pass your callback’s name as the “meta_box_cb” arg for your register_taxonomy() call.

    If you instead see a dropdown list, you can use the ‘list_cats’ filter since it passes the term object along with the name. Despite “cats” in the filter name, it works for any hierarchical taxonomy which uses the default meta box callback where the dropdown variant is used.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘tag dropdown instead of showing tag name -> tag titelform (slug)’ is closed to new replies.