0

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

Kashif Munir
  • 193
  • 1
  • 3
  • 19
  • Hello, may you can use `wp_slash()` function for this, check this out https://wordpress.stackexchange.com/a/129155/198120 – Fauzan Edris Nov 28 '22 at 03:49

2 Answers2

1

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

  • When I try to remove and add slashes after replace str and making some mistakes. Can you tell me how can I handle this? – Kashif Munir Oct 08 '20 at 18:26
  • 1
    Pardon me, I am not sure what kind of string you have, But you may better try for a formatted string json_encode(), Keep your data in a php array and then encode the array while saving. While you retrieve it, please decode it first by json_decode and set the second parameter true. Then add stripslashes_deep with individual array value rather than whole array. – Pirate of KGP Oct 09 '20 at 03:19
0

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


}
Kashif Munir
  • 193
  • 1
  • 3
  • 19