lundi 29 décembre 2014

How to throw error to user when saving post


I made a custom post type and on saving its additional data I want to check if I a published post exists by its name. It works alright if there is, but I would like to throw some notice if article is not found.



$post_exists = $wpdb->get_row("SELECT post_name FROM wp_posts WHERE post_name = '" . $_POST['article_name'] . "' AND post_type = 'post'", 'ARRAY_A');
if($post_exists)
update_post_meta($id, 'article_name', strip_tags($_POST['article_name']));
else
???


I noticed there is http://codex.wordpress.org/Class_Reference/WP_Error but I dont think that is what I want since debugging is set to false?. Error could be anything - some usual notice would be fine, but even simple javascript alert could be good. Currently it tells me that the post is saved with green lights which doesnt seem right http://s1.postimg.org/kmjjjvuvj/image.jpg





Aucun commentaire:

Enregistrer un commentaire