Title: Can you help slim down my php code?
Last modified: August 19, 2016

---

# Can you help slim down my php code?

 *  [jonoc73](https://wordpress.org/support/users/jonoc73/)
 * (@jonoc73)
 * [17 years ago](https://wordpress.org/support/topic/can-you-help-slim-down-my-php-code/)
 * Hi there,
 * I am currently creating a site for bike tours. There are 6 different price plans
   and the prices are entered using custom fields.
 * Depending if anything is entered in the custom field I am using the following
   code to display it. Also if anything is entered in any of the fields I am also
   displaying a heading.
 * I can’t help feeling however it’s a little bloated with code and just wanted 
   some advice if I can slim it down a little – with examples if you can…
 * Thanks For your help. Jono.
 *     ```
       <?php if(get_post_meta($post->ID, 'gt_price-do', true) ||
       		 get_post_meta($post->ID, 'gt_price-obso', true) ||
       		 get_post_meta($post->ID, 'gt_price-so', true) ||
       		 get_post_meta($post->ID, 'gt_price-c', true) ||
       		 get_post_meta($post->ID, 'gt_price-obdo', true) ||
       		 get_post_meta($post->ID, 'gt_price-obso', true)): ?>
       		<h4>Full Tour Price:</h4>
       		<ul>
       		<?php  if(get_post_meta($post->ID, "gt_price-do", true)): ?>
       		<li><span class="blue">Rider with Double Occupancy</span> $<?php echo get_post_meta($post->ID, 'gt_price-do', TRUE); ?></li>
       		<?php endif; ?>
       		<?php  if(get_post_meta($post->ID, "gt_price-so", true)): ?>
       		<li><span class="blue">Rider with Single Occupancy</span> $<?php echo get_post_meta($post->ID, 'gt_price-so', TRUE); ?></li>
       		<?php endif; ?>
       		<?php  if(get_post_meta($post->ID, "gt_price-c", true)): ?>
       		<li><span class="blue">Couples Price</span> $<?php echo get_post_meta($post->ID, 'gt_price-c', TRUE); ?></li>
       		<?php endif; ?>
       		<?php  if(get_post_meta($post->ID, "gt_price-obdo", true)): ?>
       		<li><span class="blue">Own Bike Double Occupancy (shared room)</span> $<?php echo get_post_meta($post->ID, 'gt_price-obdo', TRUE); ?></li>
       		<?php endif; ?>
       		<?php  if(get_post_meta($post->ID, "gt_price-obso", true)): ?>
       		<li><span class="blue">Own Bike Single Occupancy (own room)</span> $<?php echo get_post_meta($post->ID, 'gt_price-obso', TRUE); ?></li>
       		<?php endif; ?>
       		</ul>
       <?php endif; ?>
       ```
   

Viewing 1 replies (of 1 total)

 *  [zacs](https://wordpress.org/support/users/zacs/)
 * (@zacs)
 * [17 years ago](https://wordpress.org/support/topic/can-you-help-slim-down-my-php-code/#post-1073697)
 * The way I would probably do it is set a value for your custom keys, i.e.
    get_post_meta(
   $post->ID, ‘gt_price-obso’, true) will return “Own Bike Double Occupancy (shared
   room)”
 * The way I would implement this:
    <?php $keys = array(‘gt_price-do’,’gt_price-
   obso”gt_price-so’,’gt_price-c’,’gt_price-obdo’,’gt_price-obso’); $value = “”;
   foreach($keys as $key) { $tmpValue = get_post_meta($post->ID, $key, true) } ?
   > That isnt all of it but should be enough to get you going.
 * Regards,
    Zac

Viewing 1 replies (of 1 total)

The topic ‘Can you help slim down my php code?’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [zacs](https://wordpress.org/support/users/zacs/)
 * Last activity: [17 years ago](https://wordpress.org/support/topic/can-you-help-slim-down-my-php-code/#post-1073697)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
