WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Custom Columns in custom post type edit page (2 posts)

  1. mosdave
    Member
    Posted 3 years ago #

    Hi

    I have several custom post types that I have set up custom columns for in the admin edit pages. All work fine except one value (artist name in the Artist column) is repeated many times. The 'artist' column is used on all of my custom post type admin edit pages.

    I'm using

    case "artist":
    $terms = wp_get_post_terms($post->ID,'artist');
    echo $terms[0]->name;
    break;

    to get the artist name in each of my custom post types.

    I don't understand why the same artist name is getting repeated?

    Any ideas?

    Cheers

  2. mosdave
    Member
    Posted 3 years ago #

    Ok I found the solution. It seems that manage_posts_custom_column gets called while rendering *all* post type objects including posts, pages, and custom post types.

    Therefore to fix the repeating problem simply check for the post type before getting the terms.

    case "artist":
    if ($post->post_type == 'gallery') {
        $terms = wp_get_post_terms($post->ID, 'artist');
        echo $terms[0]->name;
    }
    break;

    Thanks to shibashake.com for the info, in particular this post:
    http://shibashake.com/wordpress-theme/add-custom-post-type-columns

    Cheers

Topic Closed

This topic has been closed to new replies.

About this Topic