I'm having an issue saving post meta on all post types, both default and custom. I'm hooking in to save_post to run my function, and what's happening is that the post meta gets added, but then immediately deleted. This is what I have right now:
function saveSidebarMeta($postId) {
$toAdd = $_POST['collection-topics'];
foreach ($toAdd as $topic) {
add_post_meta($postId, 'collection-topic', $topic);
}
}
add_action('save_post', 'saveSidebarMeta', 100);
Right now, I have the priority set at 100, and that does save the post meta, but then if the page is saved again the post meta gets deleted unless the correct info is added and I don't want it to be deleting and adding the data every time someone saves a post.
If the priority is set to the default 10, the data does get saved, but then immediately deleted. I know this because 1.) add_post_meta() returns the meta_key, which is then absent from the database and 2.) if I put a die() statement right after add_post_meta(), the meta data shows in the table.
I have other functions saving post meta just fine. Am I missing something really simple here? I've been looking through this issue for a while and have run out of places to look or directions to go in for a solution. Any help would be appreciated. Thanks!