我正在使用Wordpress cron每隔24小时更新每个用户的一些usermeta。为此,我使用宿主提供商提供的接口创建了一个cronjob。
Cron运行,但由于对未定义函数get\\u users()的调用出现致命错误,代码无法执行。我在许多其他地方使用过这个函数,但我不太了解,如何确保它在这里也能工作。我只需要获取使用过的id,循环每个用户id,然后循环每个用户id的每个帖子。
代码。问题在第3行:
<?php
$authors=get_users(array( \'fields\' => array( \'ID\' ) ) );
foreach($authors as $author){
// do stuff to get user I
$author_posts = get_posts( array(\'author\' => $author->id, \'numberposts\' => -1 ));
// needed to collect the total sum of views
$counter = 0;
$word_count=0;
$image_count=0;
$comment_count=0;
$daily_Views= date("d-m-Y") . \'-Views\';
$daily_Words=date("d-m-Y") .\'-Words\';
$daily_Images=date("d-m-Y") .\'-Images\';
$daily_Comments=date("d-m-Y") .\'-Comments\';
$daily_View_Pay=date("d-m-Y") .\'-View-Pay\';
$daily_Word_Pay=date("d-m-Y") .\'-Word-Pay\';
$daily_Image_Pay=date("d-m-Y") .\'-Image-Pay\';
$daily_Comment_Pay=date("d-m-Y") .\'-Comment-Pay\';
$daily_Total_Pay=date("d-m-Y") .\'-Total-Pay\';
// do stuff to get author name
foreach ( $author_posts as $post ) {
$views = absint( get_post_meta( $post->ID, \'Creation_Views\', true ) );
$word_count = str_word_count( strip_tags( get_post_field( \'post_content\', $post->ID )));
$image_count = count( get_attached_media( \'image\', $post->ID ) );
$comment_count = get_comments_number($post->ID) ;
$counter += $views;
$word_counter += $word_count;
$image_counter += $image_count;
$comment_counter += $comment_count;
}
$id= $author->id;
update_user_meta($id, $daily_Views, $counter);
update_user_meta($id, $daily_Words, $word_counter);
update_user_meta($id, $daily_Images, $image_counter);
update_user_meta($id, $daily_Comments, $comment_counter);
$View_Pay = ($counter/1000)*400;
update_user_meta($id, $daily_View_Pay, $View_Pay);
$Word_Pay= ($word_counter/1000)*10;
update_user_meta($id, $daily_Word_Pay, $Word_Pay);
$Image_Pay= ($image_counter/1000)*10;
update_user_meta($id, $daily_Image_Pay, $Image_Pay);
$Comment_Pay= ($comment_counter/1000)*10;
update_user_meta($id, $daily_Comment_Pay, $Comment_Pay);
$Total_Payment= $View_Pay + $Word_Pay + $Image_Pay+ $Comment_Pay;
update_user_meta($id, $daily_Total_Pay, $Total_Payment);
$counter = 0;
$word_counter = 0;
$image_counter = 0;
$comment_counter = 0;
}
?>
这似乎很完美,事实上,我尝试了一些网站来检查我的代码,从语法上看,它肯定是正确的,我如何确保在第3行,我的代码获得所有用户,然后在循环中,我们获得每个用户的用户id。。。