我的functions.php中有很多函数,需要直接在functions.php中调用它们。我这样做了,但是当我以这种方式调用函数时,管理面板开始工作得很慢:
function setTumblrShares($tumblrUrl){
global $wpdb;
$shareTmbArgs = array(
'posts_per_page' => -1,
'offset' => 0,
'order' => 'DESC',
'orderby' => 'date',
'post_type' => 'video',
'post_status' => 'publish',
'suppress_filters' => 0
);
$shareTumblrCountList = get_posts($shareTmbArgs);
if ($shareTumblrCountList) {
foreach ($shareTumblrCountList as $shareTumblrCountItem) {
$tumblrUrl = get_permalink($shareTumblrCountItem->ID);
$shareTumbData = getTumblrShares($tumblrUrl);
$tumblrShares = $shareTumbData["response"]["note_count"];
$table_name = $wpdb->prefix . "posts";
$wpdb->update( $table_name, array( 'tumblrShareCount' => $tumblrShares),array('ID'=>$shareTumblrCountItem->ID));
}
}
}
function getTumblrShares($tumblrUrl){
$jsonForReddit = json_decode(file_get_contents("http://api.tumblr.com/v2/share/stats?url=".$tumblrUrl),true);
return $jsonForReddit;
}
add_action('admin_menu', 'setTumblrShares');