this is a silly question, but i dont know, can anyone help me out in this

i want to echo get_post_meta() on a url, but i am getting parse error i am having a function, where in the between of url one field can be filled by the value of custom field

here is the code

($doc->load('http://twitter.com/statuses/user_timeline/' . . '.rss'));

the space between . . there i want to echo the value of my get_post_meta value,

but if i write something like this

($doc->load('http://twitter.com/statuses/user_timeline/' .echo get_post_meta() . '.rss'));

i know this step is wrong, then too i tried, i get parse error

how can i echo it???

  • leave out echo . btw a meta key argument is required from what I remember Commented Dec 17, 2010 at 14:13
  • Yea, leave out echo but you need more than just get_post_meta. It has to be get_post_meta($post->ID, 'change-this-to-your-meta-field', true); Commented Dec 17, 2010 at 14:56

1 Answer 1


Remove the echo. In PHP, you only use echo when you want to send the result as text to the browser. If you want to use the value in PHP (like you are trying to do), then you leave out the echo and add $post->ID, 'meta_field_you_want', true to get_post_meta();

  • that i tried then i am getting error, the custom field has the value which has to go into the url, and i have given $post->ID and other things but i am getting error i have to echo it so that i get that value Commented Dec 17, 2010 at 16:07
  • 1
    <code>$meta = get_post_meta($post->ID, 'your_key', true); $feed = "twitter.com/statuses/user_timeline/$meta.rss"; $doc->load($feed); </code> Commented Dec 17, 2010 at 17:34
  • 1
    Might want to add some error handling, too: if ( $meta = get_post_meta($post->ID, 'your_key', true) ) { $feed = "http://twitter.com/statuses/user_timeline/$meta.rss"; $doc->load($feed); } ... so it doesn't break if that key isn't present. Commented Dec 17, 2010 at 21:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.