Update meta feild for "Elementor" _elementor_data in admin

1k views Asked by At

I am trying to update url in 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, '_elementor_data', $metacontent1 );

But....

i tried to remove slashes and add slashes back. but after saving its changed all the content with text and lost all layout...

Thanks

2

There are 2 answers

0
Kashif Munir On BEST ANSWER

Its is not possible to change url in this way. we must need to update url in database using query..

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' ;" );/**/


}
2
Pirate of KGP On

Wordpress sanitizes and serializes data, to be inserted as string, by default.