I have a little plugin to adds a custom field with a specific format to a post. It’s sort of working, but for some reason creates duplicate entries in the DB when the user clicks the “update post” button.
The part responsible for saving the meta data is here
function saveCustomLink($post){
$linkLabel = $_POST['custom-link-label'];
$linkText = $_POST['custom-link-text'];
$linkUrl = $_POST['custom-link-url'];
if($linkLabel != "" AND $linkText != ""):
$newLink = ($linkUrl != "") ? "$linkLabel: <a href='$linkUrl' title='$linkText'>$linkText</a>" : $linkLabel . ": " . $linkText ;
add_post_meta($post, "custom-meta-link", $newLink);
endif;
}
add_action('save_post', 'saveCustomLink');
There’s a pastebin of the complete code here
I’m using the latest version of wordpress (3.0.5). Big thanks for any help.
Try with this:
You must check that you are working with a post (or page) and not with a revision,or an attachment (revisions are post with post_type=revision)