AddThis Inserts duplicate meta items
-
Currently the addthis_post_metabox::save_post function adds a meta item every time the post_save action is run. The problem stems from this section of code lines 54 through 62 of addthis_post_metabox.php
$custom_fields = get_post_custom($post_id); if (! isset ($custom_fields['addthis_exclude'][0]) ) { add_post_meta($post_id, 'addthis_exclude', 'true'); } else { update_post_meta($post_id, 'addthis_exclude', 'true' , $custom_fields['addthis_exclude'][0] ); }
From what I’ve found the problem is that when the new revision of the post that also triggers the save_post action has no meta so it triggers the
add_post_meta
section of the code which then useswp_is_post_revision
which returns the parent post id to have the meta applied to it and sinceadd_post_meta
doesn’t have the$unique
parameter set as true it adds a duplicate meta value to the parent post.Since this meta key is supposed to be unique and only has one value I found that changing the code above to this code fixed the problem for me.
if( ! update_post_meta($post_id, 'addthis_exclude', 'true' ) ) add_post_meta( $post_id, 'addthis_exclude', 'true', true );
- The topic ‘AddThis Inserts duplicate meta items’ is closed to new replies.