Support » Fixing WordPress » Custom Columns in custom post type edit page

  • Resolved mosdave

    (@mosdave)


    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

Viewing 1 replies (of 1 total)
  • mosdave

    (@mosdave)

    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

Viewing 1 replies (of 1 total)
  • The topic ‘Custom Columns in custom post type edit page’ is closed to new replies.