I have two different plugins. My custom-post-type is on the first plugin and it has some meta boxes. Now in the second plugin, I extracted the email using IMAP and stored it in the post type of the first plugin. In the below code the two variables ticket_username and ticket_email are inside a class.

for($i=1; $i<=imap_num_msg($this->conn); $i++) {
   $res = imap_headerinfo($this->conn, $i);
     $ticket_username = $res->fromaddress; //For username
     $ticket_email = $res->from[0]->mailbox . "@" . $res->from[0]->host;// For E-mail.

I assigned the username and email from the email. Now I want this email and username to be inserted into my meta boxes along with the emails.

    function custom_meta_ticket_field_callback($post) {
        wp_nonce_field( 'custom_ticket_metabox_nonce', 'faqpress_ticket_meta_fields_nonce' );
        $ticket_username = get_post_meta( $post->ID, 'ticket_username', true );
        $ticket_email     = get_post_meta( $post->ID, 'ticket_email', true );
            <label for="custom_design"><h4><?php  _e( 'Name', 'Custom' ); ?></h4></label>
            <input type="text"  id="" class="widefat" name="ticket_username" value="<?php echo esc_attr( $ticket_username ); ?>" size="25" readonly />

            <label for="design"><h4><?php  _e( 'Email', 'Custom' ); ?></h4></label>
            <input  type="email" id="" class="widefat" name="email" value="<?php echo esc_attr( $ticket_email ); ?>" size="25" readonly />



Note: The CPT and metabox are registered in a different plugin and the emails are extracted and stored in the CPT by another plugin.

1 Answer 1


The meta boxes are irrelevant. Meta boxes are just a UI for adding arbitrary forms and data to the classic editor.

What matters is how and where the data is stored. Thankfully the code you included reveals this. From your code we can see that the saved values are stored as post meta:

$faqpress_ticket_username = get_post_meta( $post->ID, 'faqpress_ticket_username', true );
$faqpress_ticket_email    = get_post_meta( $post->ID, 'faqpress_ticket_email', true );

So if you want to store the data in the same place as the meta boxes then you need to store it as post meta also. Storing post meta is as simple as using a corresponding update_post_meta():

update_post_meta( $post_id, 'faqpress_ticket_username', $value );
update_post_meta( $post_id, 'faqpress_ticket_email', $value );

You just need to make sure the $post_id and $value variables are populated appropriately.

  • How do I get the $values properly ?
    – Rohit kc
    Dec 22, 2021 at 8:18
  • I don’t know. It’s your code. Use whatever data you want to save for those fields. Dec 22, 2021 at 8:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.