Support » Plugin: Contact Form X » How to view emails

  • Resolved tezalsec

    (@tezalsec)


    Hi again šŸ™‚

    I am checking to how emails are saved in the database. I see you save them as posts. I have two questions.

    1. How do you suggest to view/list them, other than the last few in a widget? What If would want a list of all of them, including metadata?
    I did fiddle with your cpt registering function to make them available as posts in the left admin menu as “Emails”, but that wont show the meta post data.

    2. please add a “cfx_” prefix to the post metadata key elements, making them more recognizable, less generic and easier to clean.

    Thanks again. No more issues from me on this plugin šŸ™‚

    • This topic was modified 2 months ago by tezalsec.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter tezalsec

    (@tezalsec)

    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 2 months ago by tezalsec.
    Plugin Author Jeff Starr

    (@specialk)

    Glad to help:

    1) “How do you suggest to view/list them, other than the last few in a widget? What If would want a list of all of them, including metadata?”

    It’s not something that is provided by the plugin. But WordPress is very flexible and anything is possible. For example, a custom loop using get_posts or similar could be used to query the desired posts, etc.

    2) “please add a ā€œcfx_ā€ prefix to the post metadata key elements, making them more recognizable, less generic and easier to clean.”

    It is possible but may disrupt existing functionality. I will take a closer look for the next plugin update.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.