Title: post_ID within a php function
Last modified: August 19, 2016

---

# post_ID within a php function

 *  [michelrijnders](https://wordpress.org/support/users/michelrijnders/)
 * (@michelrijnders)
 * [16 years, 8 months ago](https://wordpress.org/support/topic/post_id-within-a-php-function/)
 * Hello,
 * I am totally not known with php, but try to integrate Twitter with the comments.
 * The idea is that you can click a link which generates a hashtag on Twitter. And
   under each article I wanna publish the tweets with the specific hashtag.
 * I solved the publishing, which look like:
 * `Use hashtag #MR_<?php the_ID(); ?> or <a href="http://twitter.com/home?status
   =MR_<?php the_ID(); ?>">click here</a><p>`
 * Now I wanna use WordPress built in rss reader to pull the comments on Twitter.
 *     ```
       <?php include_once(ABSPATH . WPINC . '/rss.php');
       wp_rss("http://search.twitter.com/search.atom?q=MR_<?php the_ID(); ?>)", 10); ?>
       ```
   
 * That doesn’t work. I read that you can’t nest php functions. How can show an 
   specific rss-feed under each article?

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

 *  [Zareef Ahmed](https://wordpress.org/support/users/zareef/)
 * (@zareef)
 * [16 years, 8 months ago](https://wordpress.org/support/topic/post_id-within-a-php-function/#post-1142690)
 * instead of returning the value the_ID function print the value on screen.
    So
   here is one small hack to get it done. <?php include_once(ABSPATH . WPINC . ‘/
   rss.php’); ob_start(); the_ID(); $ID=ob_get_clean(); wp_rss(“[http://search.twitter.com/search.atom?q=MR_$ID](http://search.twitter.com/search.atom?q=MR_$ID))”,
   10); ?>
 * Enjoy… In India we call it a Jugaad
 *  [Jacorre](https://wordpress.org/support/users/jacorre/)
 * (@jacorre)
 * [16 years, 8 months ago](https://wordpress.org/support/topic/post_id-within-a-php-function/#post-1142736)
 * What about using custom fields? I have a custom field called rss which stores
   the url to the rss feed for a site. I’d like to grab the value and place it into
   the wp_rss call.
 *  [Justin Tadlock](https://wordpress.org/support/users/greenshady/)
 * (@greenshady)
 * [16 years, 8 months ago](https://wordpress.org/support/topic/post_id-within-a-php-function/#post-1142738)
 *     ```
       wp_rss("http://search.twitter.com/search.atom?q=MR_{$post->ID})", 10); ?>
       ```
   
 * If you’re in a function, you’ll need to call `global $post;` before that.
 *  [Zareef Ahmed](https://wordpress.org/support/users/zareef/)
 * (@zareef)
 * [16 years, 8 months ago](https://wordpress.org/support/topic/post_id-within-a-php-function/#post-1142745)
 * btw get_the_ID() function is also there.
 *  [ciphasublime](https://wordpress.org/support/users/ciphasublime/)
 * (@ciphasublime)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/post_id-within-a-php-function/#post-1142852)
 * Hello
    Im having an issue with calling a custom field data into the feed url.
 * I basically want a page to show a different feed url based on whats been inputed
   into the custom field option. How would i implement this using this setup.
 *     ```
       <?php
       	   $feeds =  get_post_meta($post->ID, 'feeds',true);
       ?>
       <?php
       	include_once(ABSPATH.WPINC.'/rss.php'); // path to include script
       	$feed = fetch_rss('FEED-URL I WANT TO CALL FROM A CUSTOM FIELD'); // specify feed url
       	$items = array_slice($feed->items, 0, 3); // specify first item and duration
       ?>
       <?php if (!empty($items)) : ?>
       <?php foreach ($items as $item) : ?>
       <a href="<?php echo $item['link']; ?>"><?php echo $item['description']; ?></a>
       <?php endforeach; ?>
       <?php endif; ?>
       ```
   
 * thanks in advanced to anyone with a solution.
 *  [ciphasublime](https://wordpress.org/support/users/ciphasublime/)
 * (@ciphasublime)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/post_id-within-a-php-function/#post-1142853)
 * ISSUE RESOLVED!!!
 * I used $feeds as my custom field option
 *     ```
       <?php // Get RSS Feed(s)
       							include_once(ABSPATH . WPINC . '/rss.php');
       							$feeds =  get_post_meta($post->ID, 'feeds',true);
       							$rss = fetch_rss($feeds);
       							$maxitems = 5;
       							$items = array_slice($rss->items,0,$maxitems);
   
       							?>
   
       							<ul>
       							<?php if (empty($items)) echo '<li>No items</li>';
       							else
       							foreach ( $items as $item ) : ?>
       							<li><a href='<?php echo $item['link']; ?>'
       							title='<?php echo $item['title']; ?>'>
       							<?php echo $item['title']; ?>
       							</a></li>
       							<?php endforeach; ?>
       							</ul>
   
       						</div>
       ```
   
 * check out the link
    [link](http://ciphasublime.deviantart.com/)

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

The topic ‘post_ID within a php function’ is closed to new replies.

## Tags

 * [Post_ID](https://wordpress.org/support/topic-tag/post_id/)
 * [RSS](https://wordpress.org/support/topic-tag/rss/)

 * 6 replies
 * 5 participants
 * Last reply from: [ciphasublime](https://wordpress.org/support/users/ciphasublime/)
 * Last activity: [15 years, 9 months ago](https://wordpress.org/support/topic/post_id-within-a-php-function/#post-1142853)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
