0

I need to know what is wrong with my if statement here:

//EMAIL ADMIN BASED ON PROBLEM_TYPE
function new_post_creation_email() {
    global $post;
    $postid = $post->ID;
    $problem_type = get_post_meta($postid, 'problem_type', true);
    $description = the_content();
    if ($problem_type = 'phones') {
        $to = '1st email here';
    }
    elseif ($problem_type = 'computers') {
        $to = '2nd email here';
    }
    else {
        $to = '3rd email here';
    }
    $subject = "New Ticket in " . get_post_meta($postid, 'problem_type', true);
    $message = "A new ticket has been added.  Please login to view and print.";

    wp_mail($to, $subject, $message);
}

Emails are correct in actual code Currently, the message sends but the same email arrives multiple times in my 1st email address, not the correct one.

3

This is problem with your PHP syntax, not WP. You are using assignment (=) where you should be using comparison (==).

So this:

if( $problem_type = 'phones' )

should really be this:

if( 'phones' == $problem_type )

And same for other condition.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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