douchun1900 2018-09-03 09:29
浏览 59

设置post_tag所有帖子

I'm trying to add post_tag to my posts in WordPress.

...

$tag = array('tag1', 'tag2', 'tag3', 'tag4', 'tag5'); // many tag

$query_post = "SELECT * FROM wp_posts WHERE post_status='publish' LIMIT 1000";
$result_post = mysql_query($query_post);
while($row_post = mysql_fetch_array($result_post)){
$post_id = $row_post[ID];
$newtag = "";
for ($i=1; $i<=5; $i++) {
$tag = $tag[rand(0, 4)]);
$newtag .= $tag . ",";
}
wp_set_post_terms($post_id, $newtag, 'post_tag', true);
}

...

every time I run a script (for example, in a background: php tag.php >1.log 2>1.log &) I get an error: [8950772.542355] Out of memory: Kill process 32701 (php) score 156 or sacrifice child.

I increased memory_limit in php.ini on 2G, but this does not solve the problem (. What can be wrong with this simple script?

UPDATE: ok, guys. I changed the code, now it looks like this: ...

$query_post = "SELECT * FROM wp_posts WHERE post_status='publish' LIMIT 1000";
if (!$result_post = $mysqli->query($query_post)) {  exit; }
while ($row_post = $result_post->fetch_assoc()) {
    $post_id = $row_post[ID];
    for ($i=1; $i<=5; $i++) {
        $tag = str_replace("Tag", $episode_name, $tag_episode_1[rand(0, 106)]);
        $newtag .= $tag . ",";
    }   
    wp_set_post_terms($post_id, $newtag, 'post_tag', true);     
}

...

Out of memory: Kill process 32701 (php) score 156

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
    • ¥20 关于URL获取的参数,无法执行二选一查询
    • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
    • ¥15 marlin编译错误,如何解决?
    • ¥15 有偿四位数,节约算法和扫描算法
    • ¥15 VUE项目怎么运行,系统打不开
    • ¥50 pointpillars等目标检测算法怎么融合注意力机制
    • ¥20 Vs code Mac系统 PHP Debug调试环境配置
    • ¥60 大一项目课,微信小程序
    • ¥15 求视频摘要youtube和ovp数据集