Reputation: 1429
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');
Upvotes: 0
Views: 5840
Reputation: 9691
If you want to call some function inside your functions.php use the related hook or visit actions and filters and also consider checking your templates and find which hook should be used for calling which functions , you if want to modify the output use filter and if you want to perform some action use action.Depending open the job you need to use the hooks.
Upvotes: 1