Title: Problem using custom fields within WordPress functions
Last modified: August 20, 2016

---

# Problem using custom fields within WordPress functions

 *  Resolved [hrcwebmaster](https://wordpress.org/support/users/hrcwebmaster/)
 * (@hrcwebmaster)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/problem-using-custom-fields-within-wordpress-functions/)
 * I am creating a CMS, so I have run into some less common problems here. I am 
   constantly having troubles using my custom fields within a WordPress function.
   For most of these, I have found ways around them, but there’s got to be a way
   to have your cake and eat it too.
    Most recently I ran into this when wanting
   to put an RSS feed up on my pages. (No, I can’t use a widget, because the problem
   is that I need a different feed on the sidebar of each page and want to put it
   in the page template and have it pull the appropriate feed link from the page’s
   custom fields.) I used code from [http://codex.wordpress.org/Function_Reference/fetch_feed](http://codex.wordpress.org/Function_Reference/fetch_feed).
   Here’s the part I’m having trouble with: `$rss = fetch_feed('http://example.com/
   rss/feed/goes/here');` So in order to use my custom fields, I need to do this:`
   $rss = fetch_feed('<?php $key="delicious-feed"; echo get_post_meta($post->ID,
   $key,true); ?>');` Or so I thought. It won’t display anything from that feed,
   and I know for a fact it works, because I tested it first with the actual url
   before putting in the code to pull the custom fields. This has happened with 
   more than just RSS feed readers, but with many things, usually when the php code
   has to go between ”. Any tips/tricks/help is much appreciated!

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

 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/problem-using-custom-fields-within-wordpress-functions/#post-3077146)
 * It may be that $post->ID is not available. Did you declare $post as a global?
 *  Thread Starter [hrcwebmaster](https://wordpress.org/support/users/hrcwebmaster/)
 * (@hrcwebmaster)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/problem-using-custom-fields-within-wordpress-functions/#post-3077147)
 * Sorry, I don’t know about declaring $post as global, could you send me some documentation?
   I’m new to WordPress and PHP.
    Thanks!!
 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/problem-using-custom-fields-within-wordpress-functions/#post-3077149)
 * Just add `global $post;` after your function declaration.
 *     ```
       function blah_blah() {
          global $post;
          // rest of function
       }
       ```
   
 *  Thread Starter [hrcwebmaster](https://wordpress.org/support/users/hrcwebmaster/)
 * (@hrcwebmaster)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/problem-using-custom-fields-within-wordpress-functions/#post-3077166)
 * Ok I tried it this way
 *     ```
       $rss = fetch_feed('<?php $key="delicious-feed"; echo get_post_meta($post->ID,$key,true); ?>'); {
       global  $post
       if (!is_wp_error( $rss ) ) : }
       // Checks that the object is created correctly
           // Figure out how many total items there are, but limit it to 5.
           $maxitems = $rss->get_item_quantity(5);
       ```
   
 * and it gets error ” Parse error: syntax error, unexpected T_IF, expecting ‘,’
   or ‘;’ in /home/…”
    and this way
 *     ```
       $rss = fetch_feed('<?php $key="delicious-feed"; echo get_post_meta($post->ID,$key,true); ?>') {
       global  $post
       if (!is_wp_error( $rss ) ) : }
       // Checks that the object is created correctly
           // Figure out how many total items there are, but limit it to 5.
           $maxitems = $rss->get_item_quantity(5);
       ```
   
 * and get this error: “Parse error: syntax error, unexpected ‘{‘ in /home/hrcadmin/
   public_html/wp-content/themes/catch-box-child/member.php on line 126”
 * Do I need to declare the global $post before I call the custom field?
    Sorry 
   and thank you!
 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/problem-using-custom-fields-within-wordpress-functions/#post-3077167)
 * I think you are missing the semi-colon after $posts.
 *  Thread Starter [hrcwebmaster](https://wordpress.org/support/users/hrcwebmaster/)
 * (@hrcwebmaster)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/problem-using-custom-fields-within-wordpress-functions/#post-3077169)
 * Hmmm didn’t help. Error this time:
    ” Parse error: syntax error, unexpected ‘{‘
   in /home/hrcadmin/public_html/wp-content/themes/catch-box-child/member.php on
   line 126″
 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/problem-using-custom-fields-within-wordpress-functions/#post-3077170)
 * I see an extra closing brace at the end of this line:
 *     ```
       if (!is_wp_error( $rss ) ) : }
       ```
   
 * Remove that, and if it still doesn’t work, put the entire member.php file in 
   a [pastebin](http://pastebin.com) and post a link to it here.
 *  Thread Starter [hrcwebmaster](https://wordpress.org/support/users/hrcwebmaster/)
 * (@hrcwebmaster)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/problem-using-custom-fields-within-wordpress-functions/#post-3077171)
 * Ok didn’t work. I pasted it here: [http://pastebin.com/2zjRP0ze](http://pastebin.com/2zjRP0ze).
   
   Thank you for your help!!
 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/problem-using-custom-fields-within-wordpress-functions/#post-3077172)
 * You created that as a private paste, so only you can view it.
 *  Thread Starter [hrcwebmaster](https://wordpress.org/support/users/hrcwebmaster/)
 * (@hrcwebmaster)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/problem-using-custom-fields-within-wordpress-functions/#post-3077173)
 * Ooops sorry I made it public. Never used paste pin before.
 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/problem-using-custom-fields-within-wordpress-functions/#post-3077174)
 * I get no errors when I compile the code in the pastebin, so I can’t diagnose 
   the problem.
 * Do you still get the same error?
 *  Thread Starter [hrcwebmaster](https://wordpress.org/support/users/hrcwebmaster/)
 * (@hrcwebmaster)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/problem-using-custom-fields-within-wordpress-functions/#post-3077175)
 * I’m not getting an error, the page is displaying, but it’s not pulling the feed
   it should be. The custom field being pulled, “delicious-feed” is this: [http://feeds.delicious.com/v2/rss/wahousegop/alexander](http://feeds.delicious.com/v2/rss/wahousegop/alexander).
   So there are two stories that should be pulling the area “In the News” on the
   Web page and it’s not.
 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/problem-using-custom-fields-within-wordpress-functions/#post-3077176)
 * This code does not look right to me:
 *     ```
       // Get a SimplePie feed object from the specified feed source.
       $rss = fetch_feed('<?php $key="delicious-feed"; echo get_post_meta($post->ID,$key,true); ?>');
       global $post;
       ```
   
 * I believe it should be this:
 *     ```
       // Get a SimplePie feed object from the specified feed source.
       global $post;
       $key = 'delicious-feed';
       $rss = fetch_feed( get_post_meta($post->ID,$key,true) );
       ```
   
 *  Thread Starter [hrcwebmaster](https://wordpress.org/support/users/hrcwebmaster/)
 * (@hrcwebmaster)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/problem-using-custom-fields-within-wordpress-functions/#post-3077177)
 * cue >angelic voices<
    Hooray! Thank you so much!! I really appreciate it!!

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

The topic ‘Problem using custom fields within WordPress functions’ is closed to 
new replies.

## Tags

 * [custom field](https://wordpress.org/support/topic-tag/custom-field/)
 * [del.icio.us](https://wordpress.org/support/topic-tag/del-icio-us/)
 * [rss-feed](https://wordpress.org/support/topic-tag/rss-feed/)
 * [wordpress function](https://wordpress.org/support/topic-tag/wordpress-function/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 14 replies
 * 2 participants
 * Last reply from: [hrcwebmaster](https://wordpress.org/support/users/hrcwebmaster/)
 * Last activity: [13 years, 8 months ago](https://wordpress.org/support/topic/problem-using-custom-fields-within-wordpress-functions/#post-3077177)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
