Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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