取消审批对自定义帖子类型的评论

时间:2013-11-11 作者:agis

我已经注册了一个自定义帖子类型,我想在默认情况下取消对该自定义帖子类型的评论审批,而不影响设置为审批的默认帖子/页面。

我已经看过了抄本,但找不到任何与我想做的事情相关的东西。

我找到了如何显示未经批准的评论。注册自定义帖子类型的代码:

// Register Custom Post Type

function debate_post_type() {



$labels = array(
    \'name\'                => _x( \'Debates\', \'Post Type General Name\', \'text_domain\' ),
    \'singular_name\'       => _x( \'Debate\', \'Post Type Singular Name\', \'text_domain\' ),
    \'menu_name\'           => __( \'Debate\', \'text_domain\' ),
    \'parent_item_colon\'   => __( \'Parent Debate:\', \'text_domain\' ),
    \'all_items\'           => __( \'All Debates\', \'text_domain\' ),
    \'view_item\'           => __( \'View Debate\', \'text_domain\' ),
    \'add_new_item\'        => __( \'Add New Debate\', \'text_domain\' ),
    \'add_new\'             => __( \'New Debate\', \'text_domain\' ),
    \'edit_item\'           => __( \'Edit Debate\', \'text_domain\' ),
    \'update_item\'         => __( \'Update Debate\', \'text_domain\' ),
    \'search_items\'        => __( \'Search debates\', \'text_domain\' ),
    \'not_found\'           => __( \'No debates found\', \'text_domain\' ),
    \'not_found_in_trash\'  => __( \'No debates found in Trash\', \'text_domain\' ),
);
$args = array(
    \'label\'               => __( \'debate\', \'text_domain\' ),
    \'description\'         => __( \'Here you can post your debates\', \'text_domain\' ),
    \'labels\'              => $labels,
    \'supports\'            => array( \'title\', \'editor\', \'excerpt\', \'thumbnail\', \'comments\', \'custom-fields\', \'page-attributes\', \'post-formats\', ),
    \'taxonomies\'          => array( \'category\', \'post_tag\' ),
    \'hierarchical\'        => true,
    \'public\'              => true,
    \'show_ui\'             => true,
    \'show_in_menu\'        => true,
    \'show_in_nav_menus\'   => true,
    \'show_in_admin_bar\'   => true,
    \'menu_position\'       => 5,
    \'menu_icon\'           => \'\',
    \'can_export\'          => true,
    \'has_archive\'         => true,
    \'exclude_from_search\' => false,
    \'publicly_queryable\'  => true,
    \'capability_type\'     => \'page\',
);
register_post_type( \'debate\', $args );
}
// Hook into the \'init\' action
add_action( \'init\', \'debate_post_type\', 0 );
有什么建议吗?谢谢

1 个回复
SO网友:Chip Bennett

您应该能够编写一个函数,使用get_comments(), 然后遍历它们并使用设置状态wp_set_comment_status().

e、 g。

检索与中的帖子关联的所有评论debate 岗位类型:

$debate_comments = get_comments( array( \'post_type\' => \'debate\', \'status\' => \'approve\' ) );
循环检查每一个,并从批准更改为缓和:

foreach( $debate_comments as $debate_comment ) {
    wp_set_comment_status( $debate_comment, \'hold\' );
}

结束

相关推荐

在POST循环外部加载Comments.php模板

我正在通过ajax加载帖子,并使用$post = get_post( $post_ID );是否有方法加载注释。在我输出帖子后使用php模板?我尝试使用:global $withcomments; $withcomments = true; comments_template(); 但它不在循环中,因此它不加载模板。我正在尝试获取我的评论表单和任何当前的评论来显示,只是遇到了一些困难。任何帮助都将不胜感激!