打开某个帖子的评论

时间:2014-09-16 10:33:45

标签: wordpress content-management-system

任何人都知道如何在Wordpress中的特定帖子上打开评论?我试过comments_open($id);,但它不起作用。

<?php
   comments_open( get_the_ID() );
?>

非常感谢。

编辑: 我尝试通过在functions.php中指定它,没有任何改变。

add_filter( 'comments_open', 'feedbackOpen', 10, 2 );

function feedbackOpen( $open, $post_id ) {

    $post = get_post( $post_id );
    if($post->post_type == 'product'){
        if (get_post_meta($post->ID, 'Allow Comments', true)) {$open = true;}
    }else{
        return false;
    }

    return $open;
}

2 个答案:

答案 0 :(得分:1)

转到管理部门。找到特定的帖子,然后打开它以转到“编辑”页面。然后,从屏幕的右上角,单击&#34;屏幕选项&#34;。从那里,切换&#34;讨论&#34;。这将使&#34;讨论&#34;元框出现在帖子的WYSIWYG编辑器下方。在那里,您可以在此页面上勾选&#34;允许评论&#34;和&#34;允许引用和pingback。&#34;

如果要以编程方式执行此操作,可以使用以下代码:

// Update post with ID 37
$my_post = array(
    'ID'           => 37,
    'comment_status' => 'open'
);

// Update the post into the database
wp_update_post( $my_post );

答案 1 :(得分:0)

<?php comments_open( $post_id ); ?>不会对指定的帖子ID发表评论,但会返回true或false,具体取决于此帖子是否允许评论

有如何打开评论

$post = array(
   'ID'           => $post_id,
   'comment_status' => 'open'
);
wp_insert_post($post); // If given an ID will update the specified post

https://core.trac.wordpress.org/browser/tags/4.0/src/wp-includes/post.php

如何显示当前帖子的评论表单

<?php comment_form(); ?>

http://codex.wordpress.org/Function_Reference/comment_form