WordPress.org

Ready to get started?Download WordPress

Forums

How to update a meta value to the database (1 post)

  1. Wnd
    Member
    Posted 1 year ago #

    I wrote my own function to remove the comma from a meta value in the database. But the function doesn't work.

    After a research i know i can use update_post_meta(); But nothing happend. What am i doing wrong?

    This is my code so far:

    add_action('wp_insert_post', 'deleteCommaDB');
    
    function deleteCommaDB($post_id){
        $price_key = 'price';
        $getPrice = get_post_meta($post_id, $price_key, true);
        $newPrice = str_replace(array(','), '' , $getPrice);
        update_post_meta($post_id, $price_key, $newPrice, true);
        return true;
    }

    Thanx!,

Topic Closed

This topic has been closed to new replies.

About this Topic