在管理中更新“ Elementor” _elementor_data的元字段

问题描述

我正在尝试更新元素或数据中的网址。

$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,$Metacontent1 );

但是......

我尝试删除斜杠并重新添加斜杠。但是保存后更改了所有内容(含文本)并丢失了所有布局...

谢谢

解决方法

Wordpress会对数据进行清理和序列化,默认情况下将其作为字符串插入。

,

无法以这种方式更改 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 ) . "',$replace ) . "') " .
    "WHERE `meta_key` = '_elementor_data' AND post_id = '$idforupdate' ;" );/**/


}