I'm customizing the admin edit.php screen and I have a column that displays a meta key $gear. But it only lists the first value instead of returning a list of all the values. Here's the bit that matters:

add_action( 'manage_artists_posts_custom_column', 'manage_artists_columns', 10, 2 );
function manage_artists_columns( $column, $post_id ) {
    global $post;
    switch( $column ) {
        case 'gear' :
        $gear = get_post_meta( $post_id, 'gear', true ); 
            if ( empty( $gear ) )
                echo __( '' );
                printf( __( '%s' ), $gear );


        default :

I use a similar get_post_meta() call on the front end that uses

if( $gear = get_post_meta($post->ID, 'gear') 
echo implode( $gear, ', ' );

but I couldn't get it to adapt to this application. How do i get printf to output all values?

  • Why are you using __() inside a printf() call here? There's nothing to be translated. Also, what do you get with var_dump( $gear )? – Chip Bennett Nov 12 '12 at 23:28
  • Short answer? I have no idea. I've cobbled together pieces of code from the interwebs to achieve something way outside of my skill set. All I know is that it works... well, this one problem aside. by var_dump( $gear ) are you referring to the single post code? $gear is a custom field I've set up so the gear each artist uses can be attached to their profile. – kristina childs Nov 12 '12 at 23:36
$gear = get_post_meta( $post_id, 'gear', true );

… will return the last value only, because you told it do that with the last parameter. Drop it, and you will get an array of all values:

$gear = get_post_meta( $post_id, 'gear' );

Then print it with:

print join( $gear, ', ' );

And as Chip has pointed out: Do not use the translation function for values that are not translatable. And even translatable values need a text domain.

| improve this answer | |
  • JOIN!! Thank you so much. I tried so many variations of print, echo, implode, etc, just throwing spagetti at the wall. join is new to me and that did the trick. Only for anyone else this will help, the "true" needs to be removed :) (I assume that was a typo). – kristina childs Nov 12 '12 at 23:42
  • Yes, it was a typo. :) join() is an alias of implode(). – fuxia Nov 12 '12 at 23:43
  • I'm learning :) That's the main reason I am doing this by hand instead of searching for a plethora of plug-ins. Thanks again! – kristina childs Nov 12 '12 at 23:44

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.