简体   繁体   English

如何在PHP中查询Wordpress的多个SQL任务?

[英]How to query multiple SQL tasks in php for Wordpress?

I am looking for a way how to carry out multiple sql tasks using Wordpress php script. 我正在寻找一种使用Wordpress php脚本执行多个sql任务的方法。

So far, I have the following function, but it wont carry out all the tasks atm. 到目前为止,我具有以下功能,但是它无法执行atm的所有任务。

private function rename_products($product) {
    global $wpdb;

    // Replace product names and descriptions
    $sql = "UPDATE wp_posts SET post_title = REPLACE(post_title, 'Velikost Osuška', 'Osuška, Velikost');";
    $sql = "UPDATE wp_posts SET post_title = REPLACE(post_title, 'Velikost Ručník 50x100Velikost Ručník 50 x 100', 'Ručník, Velikost 50x100');";
    $sql = "UPDATE wp_posts SET post_content = REPLACE(post_content, 'Velikost Ručník 50x100Velikost Ručník 50 x 100', 'Ručník, Velikost 50x100');";
    $sql = "UPDATE wp_posts SET post_excerpt = REPLACE(post_excerpt, 'Velikost Ručník 50x100Velikost Ručník 50 x 100', 'Ručník, Velikost 50x100');";

    $wpdb->query($sql);
}

Any ideas? 有任何想法吗?

You can merge all the queries into one and get all the updated done. 您可以将所有查询合并为一个,并完成所有更新。 An update query supports multiple updates using SET statement separated by a comma. 更新查询支持使用逗号分隔的SET语句进行多个更新。

UPDATE wp_posts
SET post_title = REPLACE(post_title, 'Velikost Osuška', 'Osuška, Velikost'),
post_title = REPLACE(post_title, 'Velikost Ručník 50x100Velikost Ručník 50 x 100', 'Ručník, Velikost 50x100'),
post_content = REPLACE(post_content, 'Velikost Ručník 50x100Velikost Ručník 50 x 100', 'Ručník, Velikost 50x100'),
post_excerpt = REPLACE(post_excerpt, 'Velikost Ručník 50x100Velikost Ručník 50 x 100', 'Ručník, Velikost 50x100')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM