Is there a way to edit WordPress custom post types directly from the archive list page. For example, you would use the "list" view to edit the posts and pages in that custom post type, including all o the custom fields.
If you're using ACF, the easiest way to do this would be with ACF Quick Edit Fields plugin.
If you don't want to use a plugin, you need to:
You can add the following code to your theme's functions.php
:
// Replace 'cpt_name' with your custom post type name
function add_custom_columns ( $columns ) {
$columns['custom_field_1'] = __( 'Custom Field 1 Column Name' );
$columns['custom_field_2'] = __( 'Custom Field 2 Column Name' );
return $columns;
}
add_filter ( 'manage_cpt_name_posts_columns', 'add_custom_columns' );
function display_cf_columns ( $column, $post_id ) {
switch ( $column ) {
case 'custom_field_1':
echo get_post_meta ( $post_id, 'post_meta_1', true );
break;
case 'custom_field_2':
echo get_post_meta ( $post_id, 'post_meta_1', true );
break;
}
}
add_action ( 'manage_cpt_name_posts_custom_column', 'display_cf_columns', 10, 2 );