feed url problem
سؤال
hey hii everyone,
i have a function to fetch the videos from the rss feed of youtube, so that i can display selected videos to my blog
for that i am using this youtube-search-feed url
http://gdata.youtube.com/feeds/base/videos?q=eminem&client=ytapi-youtube-search&v=2
in the url, eminem is included, so it will display me videos of eminem, now my problem is, instead of eminem it should take my posts title name, so if i write this code
$rss = fetch_rss('http://gdata.youtube.com/feeds/base/videos?q='.the_title().'&client=ytapi-youtube-search&v=2');
then its returning me with a false video
here is my entire code
<?php
$newvar = str_replace(' ', '', the_title());
include_once(ABSPATH . WPINC . '/rss.php');
$rss = fetch_rss('http://gdata.youtube.com/feeds/base/videos?q='.$newvar.'&client=ytapi-youtube-search&v=2');
$maxitems = 1;
$items = array_slice($rss->items, 0, $maxitems);
?>
here i am using $newvar
to strip the spaces in between of the title of the posts
@rarst i change the code but now i am not getting the video
here is the code
<?php
$newvar = str_replace(' ', '', the_title());
include_once(ABSPATH . WPINC . '/feed.php');
$feed = fetch_feed('http://gdata.youtube.com/feeds/base/videos?q='.$newvar.'&client=ytapi-youtube-search&v=2');
$maxitems = 1;
$items = array_slice($feed->items, 0, $maxitems);
?>
المحلول
Don't know if this is your only issue, but you're using the_title()
to build your URI. This ECHOS the title, which is not what you want.
Instead, you should be using get_the_title().
I'd also urlencode the title, as Jan suggested.
Your best bet is to print out the YouTube URI after you build it, then try to hit it in a browser. If the results aren't right, the problem is with your URI.