Я сделал это с помощью другого крючка. Таким образом, код становится: -
add_action('comment_unapproved_to_approved', 'hgkb_update_post_content_on_comment_approval');
function hgkb_update_post_content_on_comment_approval($comment)
{
$post_id = $comment->comment_post_ID;
$comment = $comment->comment_content;
$post_type=array('hgkb','hg-questions');
if (in_array(get_post_type( $post_id ),$post_type))
{
$update_answer=wp_update_post( array('ID' => $post_id, 'post_content' => $comment) );
if($update_answer)
{
//How to reload the page or redirect to another url?
}
}
}
и затем: -
add_action('admin_footer-post.php', 'hgkb_reload_after_approval');
function hgkb_reload_after_approval()
{
global $post;
$post_type=array('hgkb','hg-questions');
if (stristr( $_SERVER['REQUEST_URI'], 'post.php' ) !== false && is_object( $post ) && in_array(get_post_type( $post->ID ),$post_type) )
{
?>
<script>
jQuery(document).ready(function(){
// Reload after 1 second when a comment approved
jQuery(document).on('click', '.vim-a', function (e) {
alert("Answer Updated!! The page will be reloaded after you click on OK. ");
setTimeout(function() {
window.location.href = "<?php echo site_url(); ?>/wp-admin/post.php?post=<?php echo $post->ID; ?>&action=edit"
}, 1000);
});
// END Reload after 1 second when a comment approved and Reload the Page when a comment approved
});
</script>
<?php
}
}