Leave a Reply

3 comments

  1. You’ll only need to run it once, but this should get all your posts, and then loop through them and update the meta.

    add_action('admin_init', 'deleteCommaDB');
    
    function deleteCommaDB(){
    
        // The Query
        $args = array ( 'posts_per_page' => -1 );
        $the_query = new WP_Query( $args );
    
        // The Loop
        while ( $the_query->have_posts() ) :
            $the_query->the_post();
    
             $price_key = 'prijs';
            $getPrice = get_post_meta( get_the_ID(), $price_key, true);
            $newPrice = str_replace(array(','), '', $getPrice);
            update_post_meta(get_the_ID(), $price_key, $newPrice);
    
        endwhile;
    
    }
    

    Your function runs only when a post is inserted. You might want to consider running on save_post and sanitizing the $_POST input in the first place.

  2. add_action(‘wp_insert_post’, ‘deleteCommaDB’); – this line calls your function only on post creation.

    In order to change all previously saved posts, you will need to add your function in a wordpress loop that gets all the posts.