(sorry for not good english)
I have a problem on my wordpress theme (custom theme). I have a box in my sidebar with my last 5 tweets. This box is called with ajax but the content will not change if I add a tweet on twitter, even on refresh page.
The way i do:
In my main.js
jQuery.ajax({
type:'POST',
data:{action:'twitter_action', username:'xxxx'},
url: "http://www.ndwi.ch/wp-admin/admin-ajax.php",
success: function(value) {
jQuery("#lasttweets").html(value)
}
});
In function.php
add_action('wp_ajax_twitter_action', 'wp_echoTwitter');
add_action('wp_ajax_nopriv_twitter_action', 'wp_echoTwitter');
function wp_echoTwitter( ){
$username = $_POST['username'];
$numb = 6;
include_once(ABSPATH.WPINC.'/rss.php');
$tweet = fetch_rss("http://search.twitter.com/search.atom?q=from:" . $username . "&rpp=" . $numb );
$text = '<ul class="twitter t' . time() . '">';
for($i=0; $i<$numb; $i++){
$text .= "<li>" . html_开发者_Python百科entity_decode( $tweet->items[$i]['atom_content'] ) . "</li>";
}
$text .= "</ul>";
die( $text );
}
Do I make something wrong ? Not a long time I work with wordpress. Thanks in advance for your help.
Problem solved. Richard M said:
When using the fetch_rss function (which is deprecated) Wordpress will cache the feed for one hour, which may be your problem.
The replacement for deprecated function is fetch_feed: http://codex.wordpress.org/Function_Reference/fetch_feed
精彩评论