您可以使用admin_notices
钩http://codex.wordpress.org/Plugin_API/Action_Reference/admin_notices
例如:
function ravs_admin_notice() {
?>
<div class="error">
<p><?php _e( \'Article with this title is not found!\', \'my-text-domain\' ); ?></p>
</div>
<?php
}
在上
publish_{your_custom_post_type}
钩
http://codex.wordpress.org/Post_Status_Transitionsfunction on_post_publish( $ID, $post ) {
// A function to perform actions when a {your_custom_post_type} is published.
$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
add_action( \'admin_notices\', \'ravs_admin_notice\' );
}
add_action( \'publish_{your_custom_post_type}\', \'on_post_publish\', 10, 2 );