phpwordpresselementorpost-meta

Update meta feild for "Elementor" _elementor_data in admin


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


Solution

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