Title: Conditional function &#8211; more than one variable
Last modified: November 27, 2016

---

# Conditional function – more than one variable

 *  [valuser](https://wordpress.org/support/users/valuser/)
 * (@valuser)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/conditional-function-more-than-one-variable/)
 * Have a function that works but i use it twice – instead of once.
 * This seems wasteful as the conditions are mutually exclusive.
 * So i should be able to use something like OR or in_array but i just dont know
   how.
 * Any help would be great and appreciated!!
 * So this is how it is at the moment.
 * In English – if the person is a Senator or Congressman then go here
 *     ```
       <?php if (strpos(get_post_meta( get_the_ID(), 'app_assignment', true ),'Senator') !== false)  { ?>
       		<a href="my-site/politicians/?>"<?php _e( '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Politicians', APP_PR ); ?></a>	
       			<?php } ?>
   
       <?php if (strpos(get_post_meta( get_the_ID(), 'app_assignment', true ),'Congressman') !== false)  { ?>
       		<a href="my-site/politicians/?>"<?php _e( '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Politicians', APP_PR ); ?></a>	
       			<?php } ?>
       ```
   
 * I should be able to put this into one statement but … just need help! Please!

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Moderator [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/)
 * (@sterndata)
 * Volunteer Forum Moderator
 * [9 years, 6 months ago](https://wordpress.org/support/topic/conditional-function-more-than-one-variable/#post-8484514)
 * strpos can take an array as the needle:
 *     ```
       <?php
       $res = get_post_meta( get_the_ID(), 'app_assignment', true ) );
       if (strpos($res, array('Senator','Congressman')) !== false)  { ?>
       		<a href="my-site/politicians/?>"<?php _e( '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Politicians', APP_PR ); ?></a>	
       <?php } ?>
       ```
   
 * [http://stackoverflow.com/questions/6284553/using-an-array-as-needles-in-strpos](http://stackoverflow.com/questions/6284553/using-an-array-as-needles-in-strpos)
 *  Thread Starter [valuser](https://wordpress.org/support/users/valuser/)
 * (@valuser)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/conditional-function-more-than-one-variable/#post-8485578)
 * Many thanks!
    Convinced that its almost there! Removed extra ‘)’ from line 2.
   for line 3 at the moment there is an error: Warning: strpos(): needle is not 
   a string or an integer tried adding return true; to line 3 but same error

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Conditional function – more than one variable’ is closed to new replies.

## Tags

 * [php](https://wordpress.org/support/topic-tag/php/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [valuser](https://wordpress.org/support/users/valuser/)
 * Last activity: [9 years, 6 months ago](https://wordpress.org/support/topic/conditional-function-more-than-one-variable/#post-8485578)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
