0

I have registered a custom post type and I want to unapprove comments by default on this custom post type without affecting the default posts/pages which is set to approve.

I've looked through the CODEX but I can not find anything related to what I'm trying to do.

I've found just how can I display the un-approved comments. Code for registering custom post type:

// 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 );

Any suggestions on how can I do this ? Thanks!

  • Please edit your question to include any/all current, relevant code, including registering of the CPT and any current comment handling for the CPT. – Chip Bennett Nov 11 '13 at 15:33
  • Now, what do you mean by "unapprove comments by default on this custom post type"? – Chip Bennett Nov 11 '13 at 16:00
  • I mean that I want the comments inside this custom post type to be unapproved. – agis Nov 11 '13 at 16:07
  • What does that mean? Are you saying that you want all comments to posts in this CPT to be moderated by default? Or you want currently approved comments for posts in this CPT to be changed to unapproved? – Chip Bennett Nov 11 '13 at 16:09
  • I want currently approved comments for posts in this CPT to be changed to unapproved – agis Nov 11 '13 at 16:14
1

You should be able to write a function that fetches all comments by comment type using get_comments(), then loop through them and set status using wp_set_comment_status().

e.g.

Retrieve all comments associated with posts in the debate post type:

$debate_comments = get_comments( array( 'post_type' => 'debate', 'status' => 'approve' ) );

Loop through each one, and change from approved to moderated:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.