Skip Navigation

[Resolved] Reorder custom field columns in custom post admin

This support ticket is created 3 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 5 replies, has 3 voices.

Last updated by Paul Bowman 3 years, 6 months ago.

Assisted by: Waqar.

Author
Posts
#2097131

I’m trying to find out whether there’s a way to move custom post field columns that have been added to a custom post type admin listing in “Edit Post Type,” relative not to each other but to the standard admin columns (“Title,” “Date,” “Author,” &c.).

To move admin columns ordinarily, one uses a “manage_posts” filter something like this:

function myfunc_reorder_columns( $columns ) {
    $new_columns = array();
    foreach( $columns as $key => $value ) {
        if ( $key == 'date' )
            $new_columns['author'] = 'Author'; // Move author column before date column
        $new_columns[$key] = $value;
    }
    return $new_columns;
}
add_filter( 'manage_mycustomposttype_posts_columns', 'myfunc_reorder_columns' );

If instead of one of the standard columns I use the name of a Types custom field that I’ve added to the admin columns, this filter doesn’t do anything. Evidently the added custom field columns aren’t the same kind of thing, in the admin page view, as the standard columns.

Is there a way to move added custom field columns relative to standard admin columns?

#2097593

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Paul

I'm not sure whether it is possible, but I would suggest first that you add your callback to the filter with a higher priority so that it runs after other callbacks (in case Types uses the same filter to insert its fields as columns), e.g. 100 or higher.

Also, bear in mind that Types custom fields have a prefix of wpcf-, so a custom field with a slug of due-date actually has a post meta key of wpcf-due-date, and that is likely what would be required here.

#2097689

{ticket status updated}

#2098401

I’d thought of the need to add the wpcf- prefix, but hadn’t considered firing order. Including a prioritization value did it. Thank you!

I’ll just note that for what I needed, which entails moving several columns, I didn’t get the result I needed with a single function. Some recommendations to be found in Stack Exchange and discussion elsewhere suggest that multiple columns should be moveable using a single function, but what worked for me looks like this:

function move_field_A_column( $columns ) {
    $new_cols = array();
    foreach( $columns as $key => $value ) {
        if ( $key == 'date' )
            $new_cols['wpcf-field-A'] = '';
        $new_cols[$key] = $value;
    }
    return $new_cols;
}
function move_field_B_column( $columns ) {
    $new_cols = array();
    foreach( $columns as $key => $value ) {
        if ( $key == 'wpcf-field-A' )
            $new_cols['wpcf-field-B'] = '';
        $new_cols[$key] = $value;
    }
    return $new_cols;
}
add_filter( 'manage_edit-mycustomposttype_columns', 'move_field_A_column', 100 );
add_filter( 'manage_edit-mycustomposttype_columns', 'move_field_B_column', 100 );
#2098407

test

#2098651

Apologies, I meant to mark this resolved.

Adding callback prioritization did it. Thank you.