0

I have a custom post type that I want people to leave messages but I dont want to call it "comment". How can I replicate the comment functionality and call it something else for a custom post type?

I dont want these to show up on the general comment section of WordPress dashboard, something exactly like comments just for a custom post type.

2
  • So you have 2 questions, how do I implement a custom comments template for a particular post type with different language strings, and how do I show comments on a custom post type on a separate screen?
    – Tom J Nowell
    Commented Jun 29, 2017 at 22:52
  • @TomJNowell yes, I want to have a comment template for custom post types and show those comments in the dashboard under the post type.
    – BobsBurger
    Commented Jun 29, 2017 at 22:57

1 Answer 1

1

You can still use the core comment functionality for the custom post type, then filter the edit-comments.php admin screen and create a new admin page with the required comments table.

Step 1. Removing the comments from the edit-comments.php admin screen can be done by using the comments_clauses filter:

<?php

// Remove comments for specific post type ('project' in this case)
function exclude_comments_on_post_type( $clauses, $wp_comment_query ) {
    global $wpdb;
    if ( ! $wp_comment_query -> query_vars['post_type' ] ) {
        $clauses['where'] .= $wpdb->prepare( " AND {$wpdb->posts}.post_type != %s", 'project' );
    }
    return $clauses;
}

// Load the above only on the needed admin screen
function exclude_comments_on_post_type_hook( $screen ) {
    if ( $screen->id == 'edit-comments' ) {
        add_filter( 'comments_clauses', 'exclude_comments_on_post_type', 10, 2 );
    }    
}

// Execute the hook
add_action( 'current_screen', 'exclude_comments_on_post_type_hook', 10, 2 );

Step 2. In order to display those comments elsewhere in the admin interface, you'll need to create a new admin page using the add_menu_page() function and insert a custom WP_List_Table instance that will show the comments on that post type. Since it's a farily long read, I'll just post one of the links here without pasting all the details: https://www.sitepoint.com/using-wp_list_table-to-create-wordpress-admin-tables/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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