I have a lot of functions in my functions.php and need to call them directly inside functions.php. I did this in this way but admin panel started to work very slowly when am calling functions in this way:
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');
myFunction.pre_get_posts, not tested but still believes it may help you.