Title: How to insert php inside php&#8230;
Last modified: August 21, 2016

---

# How to insert php inside php…

 *  Resolved [starflow](https://wordpress.org/support/users/starflow/)
 * (@starflow)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/how-to-insert-php-inside-php/)
 * I am using wp-favorites plugin in a classipress site
 * My aim is to incle the ad price in the page layout in the favorites page
 * I am trying to add some php code into the page template file, but not having 
   much luck
 * Here is the existing code:
 * _[please use the ‘code’ button to mark any posted code – the code below is broken;
   [http://codex.wordpress.org/Forum\_Welcome#Posting\_Code](http://codex.wordpress.org/Forum_Welcome#Posting_Code)]_
 * > <?php
   >  echo “<div class=’wpfp-span’>”; if (!empty($user)): if (!wpfp_is_user_favlist_public(
   > $user)): echo “$user’s Favorite Posts.”; else: echo “$user’s list is not public.”;
   > endif; endif;
   >  if ($wpfp_before):
   >  echo “<p>”.$wpfp_before.”</p>”; endif;
   >  echo “
    - “;
       if ($favorite_post_ids): foreach ($favorite_post_ids as $post_id) { $p
      = get_post($post_id); global $post; echo “
    - <h3>”;
       echo “[post_title .”‘>” . $p->post_title . “](https://wordpress.org/support/topic/how-to-insert-php-inside-php/".get_permalink($post_id)."?output_format=md)
      </h3>”;
    -  echo “[post_title .”‘>”;
       if(get_post_meta($post_id, ‘images’, true)) cp_single_image_legacy(
      $post_id, get_option(‘medium_size_w’), get_option(‘medium_size_h’)); else 
      cp_get_image($post_id, ‘medium’, 1); echo ““; echo substr(strip_tags($p->post_content),
      0, 250).”…”; echo “”; wpfp_remove_favorite_link($post_id); echo “
    - “;
       }
    -  else:
       echo “
    - “;
       echo $wpfp_options[‘favorites_empty’]; echo “
    - “;
       endif; echo “
 * “;
    wpfp_clear_list_link(); echo “</div>”; wpfp_cookie_warning(); ?>
 * The php code I want to insert is:
 * > <?php if ( get_post_meta( $post->ID, ‘price’, true ) ) cp_get_price( $post-
   > >ID, ‘price’ ); else cp_get_price( $post->ID, ‘cp_price’ ); ?>
 * How can I do this?
 * I did just try adding the code like this:
 * if ( get_post_meta( $post->ID, ‘price’, true ) ) cp_get_price( $post->ID, ‘price’);
   else cp_get_price( $post->ID, ‘cp_price’ );
 * but it did not work ie: it does not call up the price and display it in the page
 * Any help will be greatly appreciated – thank you

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/how-to-insert-php-inside-php/#post-3660695)
 * please re-post the code – and follow the forum guidelines [http://codex.wordpress.org/Forum_Welcome#Posting_Code](http://codex.wordpress.org/Forum_Welcome#Posting_Code)
 *  Thread Starter [starflow](https://wordpress.org/support/users/starflow/)
 * (@starflow)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/how-to-insert-php-inside-php/#post-3661044)
 * I am using wp-favorites plugin in a classipress site
 * My aim is to incle the ad price in the page layout in the favorites page
 * I am trying to add some php code into the page template file, but not having 
   much luck
 * Here is the existing code:
 *     ```
       <?php
           echo "<div class='wpfp-span'>";
           if (!empty($user)):
               if (!wpfp_is_user_favlist_public($user)):
                   echo "$user's Favorite Posts.";
               else:
                   echo "$user's list is not public.";
               endif;
           endif;
   
           if ($wpfp_before):
               echo "<p>".$wpfp_before."</p>";
           endif;
   
           echo "<ul>";
           if ($favorite_post_ids):
               foreach ($favorite_post_ids as $post_id) {
                   $p = get_post($post_id);
       			global $post;
       			echo "<li><h3>";
                   echo "<a href='".get_permalink($post_id)."' title='". $p->post_title ."'>" . $p->post_title . "</a></h3>";
   
       			$price = get_post_meta( $post->ID, 'price' );
       			echo $price;
   
       			if(get_post_meta($item->post_id, 'cp_price', true));
   
                   if ( get_post_meta( $post->ID, 'price', true ) ) cp_get_price_legacy( $post->ID ); else cp_get_price( $post->ID, 'cp_price' );
   
                   echo "<a href='".get_permalink($post_id)."' title='". $p->post_title ."'>";
                   if(get_post_meta($post_id, 'images', true)) cp_single_image_legacy($post_id, get_option('medium_size_w'), get_option('medium_size_h')); else cp_get_image($post_id, 'medium', 1);
                   echo "</a>";
                   echo substr(strip_tags($p->post_content), 0, 250)."...";
                   echo "<br />";
                   wpfp_remove_favorite_link($post_id);
                   echo "</li>";
                  }
   
           else:
               echo "<li>";
               echo $wpfp_options['favorites_empty'];
               echo "</li>";
           endif;
           echo "</ul>";
           wpfp_clear_list_link();
           echo "</div>";
           wpfp_cookie_warning();
       ?>
       ```
   
 * The php code I want to insert is:
 *     ```
       <?php if ( get_post_meta( $post->ID, 'price', true ) ) cp_get_price( $post->ID, 'price' ); else cp_get_price( $post->ID, 'cp_price' ); ?>
       ```
   
 * How can I do this?
 * I did just try adding the code like this:
 *     ```
       if ( get_post_meta( $post->ID, 'price', true ) ) cp_get_price( $post->ID, 'price' ); else cp_get_price( $post->ID, 'cp_price' );
       ```
   
 * but it did not work ie: it does not call up the price and display it in the page
 * Any help will be greatly appreciated – thank you

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

The topic ‘How to insert php inside php…’ is closed to new replies.

## Tags

 * [get_post_meta](https://wordpress.org/support/topic-tag/get_post_meta/)
 * [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: [starflow](https://wordpress.org/support/users/starflow/)
 * Last activity: [13 years, 1 month ago](https://wordpress.org/support/topic/how-to-insert-php-inside-php/#post-3661044)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
