Jump to content

if statement to call custom field in WordPress


Recommended Posts

Hi all,


I've been struggling to get an if statement to work. I'm new to PHP so bear with me!


I have an events listing page where I pull a value from a custom field to display a 'buy tickets' button. I can get the button to display and it works well but what I need to do is customise the code so if there is no ID present, then a piece of text displays. Any pointers appreciated.


This is one method Im using for custom fields which works well - the if statement works here also.

        <?php $event_location = get_post_meta($post->ID, 'Event_Location', true);
			if ($event_location) {
        <?php echo $event_location; ?>
        <?php } else { ?>
      <p>No Location Available.</p>
      <?php } ?>


This code pulls in the buy tickets button but I cant figure out how to create an if statement with it! grrrr... :shrug:


 $values = get_post_custom_values('Product_ID');
echo get_button_code_for_product($values[0]);


I would like it to look for the ID and if it can't find it then displays ' No Product ID' or some such text.


Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.