1

i have two custom fields, and i want to add it to asnwer-question plugin email, when user posts new question - i get email with question details and i need those two custom fields in that email.

My custom fields (post_meta values):

        $key_1_value = get_post_meta( get_the_ID(), 'user_date', true );
        // Check if the custom field has a value.
        if ( ! empty( $key_1_value ) ) {
            echo $key_1_value;
        
        $key_2_value = get_post_meta( get_the_ID(), 'user_city', true );
        // Check if the custom field has a value.
        if ( ! empty( $key_2_value ) ) {
            echo $key_2_value;

And there is code snippet where plugin send email with details:

public function ap_after_new_question( $question_id ) {
    $args = array();

    $admin_emails = $this->get_admin_emails( 'email_admin_new_question' );

    if ( ! empty( $admin_emails ) ) {
        $args['users'] = $admin_emails;
    }

    // Return if no users.
    if ( empty( $args['users'] ) ) {
        return;
    }

    $question     = ap_get_post( $question_id );
    $args['tags'] = array(
        '{asker}'            => ap_user_display_name( $question->post_author ),
        '{question_title}'   => $question->post_title,
        '{question_link}'    => wp_get_shortlink( $question->ID ),
        '{question_content}' => apply_filters( 'the_content', $question->post_content ),
        '{question_excerpt}' => ap_truncate_chars( wp_strip_all_tags( $question->post_content ), 100 ),
    );
    
    add_action('wp_head', 'output_all_postmeta' );
    function output_all_postmeta() {

        $postmetas = get_post_meta(get_the_ID());

        foreach($postmetas as $meta_key=>$meta_value) {
            echo $meta_key . ' : ' . $meta_value[0] . '<br/>';
        }
    }

    $email = new EmailHelper( 'new_question', $args );
    $email->send_emails();
}

How i can add those two post_meta values to email?

modeman
  • 31
  • 8

0 Answers0