1

there are a "posts" list at admin page, and you can see each post creation date, tags, authors... I have custom tags, which are not appears here:

enter image description here

how to make it shown? They are registered already:

register_taxonomy(
    "custom_CUSTOM_tag", //taxonomy
    "post",
    array(
        'hierarchical' => false,
        'label' => 'title',
        'singular_name' => 'title',
        'rewrite' => true,
        'query_var' => true,
        'labels' => [
            'add_new_item' => 'new',
        ],
        'public' => true
    )
);
2

You just need to add 'show_admin_column' => true to your taxonomy parameters:

'show_admin_column'
(bool) Whether to display a column for the taxonomy on its post type listing screens. Default false.

So,

register_taxonomy(
    "custom_CUSTOM_tag", //taxonomy
    "post",
    array(
        'hierarchical'      => false,
        'label'             => 'title',
        'singular_name'     => 'title',
        'rewrite'           => true,
        'query_var'         => true,
        'labels'            => [
            'add_new_item' => 'new',
        ],
        'public'            => true,
        // Add this line:
        'show_admin_column' => true,
    )
);

Update

so far good, but it adds another column. Cant I append tags into the "built-in" column?

Yes, you can, and one way is by using the post_column_taxonomy_links hook. Here's an example which appends the custom tags (or terms in the title taxonomy) to the default "Tags" column in the posts list table:

But first off, please remove the 'show_admin_column' => true, from your taxonomy parameters.

add_filter( 'post_column_taxonomy_links', 'my_post_column_taxonomy_links', 10, 2 );
function my_post_column_taxonomy_links( $term_links, $taxonomy ) {
    global $post;

    if ( 'post_tag' === $taxonomy && is_object( $post ) ) {
        $terms = get_the_terms( $post->ID, 'title' ); // be sure the taxonomy is correct

        if ( is_array( $terms ) ) {
            foreach ( $terms as $term ) {
                $term_links[] = sprintf( '<a href="%s">%s</a>',
                    esc_url( get_edit_term_link( $term->term_id, $term->taxonomy, 'post' ) ),
                    esc_html( $term->name )
                );
            }
        }
    }

    return $term_links;
}

And BTW, that singular_name actually belongs in the labels item, so you should correct it. :)

3
  • 1
    This is a lot easier than what I was just attempting to write out as an answer. Lol! – Tony Djukic Mar 16 at 15:40
  • hmmm, so far good, but it adds another column. Cant I append tags into the "built-in" column? – user203436 Mar 16 at 15:42
  • @user203436, does the Update help? – Sally CJ Mar 16 at 17:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.