Using WordPress ‘get_default_comment_status()’ PHP function

The get_default_comment_status() WordPress PHP function retrieves the default comment status for a specified post type.

Usage

get_default_comment_status( $post_type, $comment_type );

Custom Example:

// Set post type to 'page' and comment type to 'comment'
$post_type = 'page';
$comment_type = 'comment';
$default_status = get_default_comment_status( $post_type, $comment_type );
echo $default_status; // Output: 'open' or 'closed'

Parameters

  • $post_type (string) – Optional. The post type for which to get the default comment status. Default is ‘post’.
  • $comment_type (string) – Optional. The comment type for which to get the default comment status. Default is ‘comment’.

More information

See WordPress Developer Resources: get_default_comment_status()

Examples

Get default comment status for blog posts

This example retrieves the default comment status for regular blog posts.

$post_type = 'post';
$comment_type = 'comment';
$default_status = get_default_comment_status( $post_type, $comment_type );
echo $default_status; // Output: 'open' or 'closed'

Get default comment status for custom post type ‘product’

This example retrieves the default comment status for a custom post type called ‘product’.

$post_type = 'product';
$comment_type = 'comment';
$default_status = get_default_comment_status( $post_type, $comment_type );
echo $default_status; // Output: 'open' or 'closed'

Get default comment status for pages

This example retrieves the default comment status for pages.

$post_type = 'page';
$comment_type = 'comment';
$default_status = get_default_comment_status( $post_type, $comment_type );
echo $default_status; // Output: 'open' or 'closed'

Get default comment status for custom comment type ‘review’

This example retrieves the default comment status for a custom comment type called ‘review’.

$post_type = 'post';
$comment_type = 'review';
$default_status = get_default_comment_status( $post_type, $comment_type );
echo $default_status; // Output: 'open' or 'closed'

Get default comment status for a custom post type and custom comment type

This example retrieves the default comment status for a custom post type called ‘portfolio’ and a custom comment type called ‘testimonial’.

$post_type = 'portfolio';
$comment_type = 'testimonial';
$default_status = get_default_comment_status( $post_type, $comment_type );
echo $default_status; // Output: 'open' or 'closed'