0

Hi i have a 'tour' custom post types and when i add a custom column at this post type there is not any custom column at tour post type my code is here

function tour_price_col( $column, $post_id){
switch ( $column ) {
    case 'price':
        echo get_post_meta( $post_id, 'tour-price', true );
        break;
    case 'test':
        echo "salam";
        break;
   }
}
add_action('manage_tour_posts_custom_column', 'tour_price_col', 10 ,2);
2

First, you need to declare/register the new columns:

add_filter( 'manage_tour_posts_columns', 'cyb_add_new_columns' );
function cyb_add_new_columns() {
        $columns['price'] = __('Price column title', 'cyb-textdomain' );
        $columns['test']  = __('Test column title', 'cyb-textdomain' );
        return $columns;
}

Then, you can print the content of the column for each post:

add_action('manage_tour_posts_custom_column', 'tour_price_col', 10 ,2);
function tour_price_col( $column, $post_id){
  switch ( $column ) {
    case 'price':
        echo get_post_meta( $post_id, 'tour-price', true );
        break;
    case 'test':
        echo "salam";
        break;
   }
}
  • How can i rearrange columns in table? – user3725280 Jul 21 '16 at 13:47
  • You need to insert the new elements in the $columns array in the position you desire. There are plenty of examples in Stackoverflow. For example, this one, this one or this one. – cybmeta Jul 21 '16 at 16:59

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.