Zach Smith
Zach Smith

Reputation: 5704

How to show custom post type column before date column

I am using the following code to output columns pertaining to a CPT:

//set up new column to show custom meta theme_color
function pr_testimonials_column($column) {
    $column['testimonial_person_tagline'] = 'Person Tagline';

    return $column;
}

add_filter('manage_testimonials_posts_columns', 'pr_testimonials_column');

//show custom column data
function pr_show_testimonials_column($name) {
    global $post;
    switch ($name) {
        case 'testimonial_person_tagline':
            $testimonial_person_tagline = get_post_meta($post->ID, '_testimonial_person_tagline', true);
            echo $testimonial_person_tagline;
    }
}

add_action('manage_testimonials_posts_custom_column',  'pr_show_testimonials_column');

The result is this, with the date first and the columns second. How can I modify my code to show all of my custom columns first, and date column last? enter image description here

Upvotes: 3

Views: 1617

Answers (1)

Dipak Kumar Pusti
Dipak Kumar Pusti

Reputation: 1723

Find the key for the Date column, next step to unset it and then set after adding your custom column,

function pr_testimonials_column($column) {

    // Remove Date
    unset($column['date']);

    $column['testimonial_person_tagline'] = 'Person Tagline';
    $column['date'] = 'Date';

    return $column;
}
add_filter('manage_testimonials_posts_columns', 'pr_testimonials_column');

Hope this one helps.

Upvotes: 4

Related Questions