0

我正在尝试更新 elementor 数据中的 url。

$metacontent = get_post_meta($idforupdate, '_elementor_data',true);
$with_slash = stripslashes_deep($metacontent);
$with_slash = str_replace($value, $url_1, $with_slash);

$metacontent1 = str_replace("/", "\/", $with_slash);
update_post_meta( $idforupdate, '_elementor_data', $metacontent1 );

但....

我试图删除斜线并添加斜线。但是在保存后它用文本更改了所有内容并丢失了所有布局......

谢谢

4

2 回答 2

1

默认情况下,Wordpress 对数据进行清理和序列化,以字符串形式插入。

于 2020-10-08T16:39:00.193 回答
0

无法以这种方式更改 url。我们必须需要使用查询更新数据库中的 url..

function update_elementor_url($search,$replace,$idforupdate){
    global $wpdb;    
    $rows_affected = $wpdb->query(
    "UPDATE {$wpdb->postmeta} " .
    "SET `meta_value` = REPLACE(`meta_value`, '" . str_replace( '/', '\\\/', $search ) . "', '" . str_replace( '/', '\\\/', $replace ) . "') " .
    "WHERE `meta_key` = '_elementor_data' AND post_id = '$idforupdate' ;" );/**/


}
于 2021-01-15T06:18:56.610 回答