• 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)

    (@sterndata)

    Volunteer Forum Moderator

    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

    Thread Starter valuser

    (@valuser)

    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.