Support » Fixing WordPress » If function with multiple "answers"

  • Resolved petersandeen



    Sorry about the title, I didn’t know how to ask this more clearly/concisely. (I also tried to search for the answer but came up with nothing because I didn’t quite know what I’m looking for…)

    I want to add several possible “answers” into an if-statement.

    For example: if(in_category(‘birds’ OR ‘mammoths’)):

    Is it even possible to add multiple possibilities? I know I can add multiple elseif-statements and get the same result, but I’d like to keep the code shorter…

    Help is much appreciated 🙂

Viewing 7 replies - 1 through 7 (of 7 total)
  • yes…

    if(in_category(birds)) {
    echo "sdada"
    elseif (in_category(mammoths)) {
    echo "sadasd"
    elseif(......) {.....}

    YOu can add as many else if statements as you want…

    Thank you Ishaan for your reply.

    But as I mentioned in the original question, I know I can add else if statements, but I’d like to add more “answers” into the first if statement to keep the code shorter. There will be more than 20 else if statements (all with a bunch of code) if I go that road.

    If it’s not possible to have multiple answers in one if statement, I’ll have to use multiple else if’s…

    so this is what you want (|| is used for OR) —>

    if(in_category("birds" || "mammoths" || "animals")) {
    echo "dasdasda"

    Ok so this is possible:
    if(in_category('birds')|| in_category('mammoths')):
    you can learn more about it here or here
    Have a nice one

    Thank you so much Ishaan 🙂

    That’s exactly what I was looking for.

    Out of curiosity, is it possible to combine two different functions in one if statement? In other words: if(in_category(‘birds’) OR has_tag(‘mammoths’)):

    Thank you jnhghy, you answered before I even could ask… 😀

    Your welcome

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘If function with multiple "answers"’ is closed to new replies.