WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Update post meta function is deleting post meta data.

[Resolved] Update post meta function is deleting post meta data.

Viewing 5 replies - 1 through 5 (of 5 total)
  • I can use the get_post_meta function to retrieve custom meta data I manually enter into my page. However the update_post_meta function only deletes the data stored in the custom meta variable. It never retreives the data. I have tried it with several different variable names and the deleting data behavior is the same.
    Also I am trying to get post meta from a page rather than a post if that makes any difference.

    Thanks!!
    –christopher

    I have tried a few different things.
    I tried to manually delete the value of the custom meta variable from the page screen and then use the add_post_meta function to add it instead of trying to update. No post_meta variable name or value was added.

    I also tried to use the delete_post_meta function followed by the add_post_meta function. Again, nothing was added.

    Interestingly, I am using the update_post_meta function only two lines later to update a custom date field and it works fine. Both updates are to custom post meta on the same page. One works, the other does not.

    Thanks,
    christopher

    When I try to include the $prev_value parameter in the update_post_meta function, the meta data still disappears.

    I’ll keep trying new things.
    Thanks,
    christopher

    I looked in my database at the wp_postmeta table and saw several entries from page ‘1054’ and meta_key ‘freeimage_filename’

    The stored meta value is as follows: O:16:"SimpleXMLElement":1:{i:0;s:14:"rice-paper.jpg";}
    When I echo the value in my variable just before updating the meta, the value printed is rice-paper.jpg.

    Why does update_post_meta not put in the value rice-paper.jpg instead of putting in the other?

    Thanks,
    christopher

    I figured it out.
    This is what I had to do.
    I had to use the sprintf function.
    sprintf("%s", $freebackgrounds->background[$i]->imagefilename)
    This converted the xml data into a string format would could be a string value stored in a variable.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Resolved] Update post meta function is deleting post meta data.’ is closed to new replies.
Skip to toolbar