在WordPress中批准评论时重定向到URL

在WordPress中批准评论时重定向到URL,wordpress,redirect,hook,Wordpress,Redirect,Hook,我正在处理一个自定义的帖子类型,其中的帖子内容将使用已批准的评论内容进行更新 我的代码是:- 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

我正在处理一个自定义的帖子类型,其中的帖子内容将使用已批准的评论内容进行更新

我的代码是:-

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('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
    }
}
add_action('admin_footer-post.php','hgkb_reload_after_approval');
函数hgkb_批准后重新加载_()
{
全球$员额;
$post_type=数组('hgkb','hg-questions');
if(stristr($\u SERVER['REQUEST\u URI'],'post.php')!==false&&is\u对象($post)&&in\u数组(get\u post\u type($post->ID),$post\u类型))
{
?>
jQuery(文档).ready(函数(){
//评论获得批准后1秒后重新加载
jQuery(document).on('click','vim-a',函数(e){
警告(“回答更新!!点击“确定”后页面将重新加载”);
setTimeout(函数(){
window.location.href=“/wp admin/post.php?post=&action=edit”
}, 1000);
});
//评论批准后1秒结束重新加载,评论批准后重新加载页面
});