I got the list view working with below code, and used an export plugin to export the emails π Perhaps you could consider adding an option under advanced like “Do you want the email in a list view?”
Adjustment to your code in contactformx_register_post_type()
function contactformx_register_post_type() {
$labels = array(
"name" => __( "Emails", "Plural name" ),
"singular_name" => __( "Email", "Single name" ),
'all_items' => __('All Emails'),
'view_item' => __('View Emails'));
register_post_type('cfx_email',
array('public' => false,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'exclude_from_search' => true,
'labels' => $labels,
'public' => false,
'publicly_queryable' => false,
'show_ui' => true,
'capability_type' => "post",
'supports' => array('title', 'editor', 'custom-fields')));
}
Extra functions to add columns and include metadata values in list view:
add_filter( 'manage_cfx_email_posts_columns', 'add_cfx_email_metadata_columns',15 );
function add_cfx_email_metadata_columns($columns) {
//add columns
return array_merge($columns,
array(
'post_content' => __('Message'), // not metdata
'name' => __('Name'),
'email' =>__( 'Email'),
'custom' => __('Custom'),
'agree' => __('Agreed')));
}
add_action( 'manage_cfx_email_posts_custom_column' , 'add_cfx_email_metadata_values', 10, 2 );
function add_cfx_email_metadata_values( $column ) {
global $post;
switch ( $column ) {
case 'post_content':
$postdata = get_post_field( 'post_content', $post->ID );
echo $postdata;
break;
case 'email':
$metadata = get_post_meta( $post->ID, 'email', true );
echo $metadata;
break;
case 'name':
$metadata = get_post_meta( $post->ID, 'name', true );
echo $metadata;
break;
case 'custom':
$metadata = get_post_meta( $post->ID, 'custom', true );
echo $metadata;
break;
case 'agree':
$metadata = get_post_meta( $post->ID, 'agree', true );
echo $metadata;
break;
}
}
π
-
This reply was modified 5 years, 9 months ago by
tezalsec.