Jump to content

if statement to call custom field in WordPress


dangermoose

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.

<div>
      <p><strong>Location:</strong>
        <?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 } ?>
      </p>
    </div>

 

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

 

 <div>
      <p>
    <?php
 $values = get_post_custom_values('Product_ID');
echo get_button_code_for_product($values[0]);
?>
      </p>
    </div>

 

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 thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.