voodo
voodo

Reputation: 15

Open comments on a certain Post

anyone know how can i open comments on a specific post in Wordpress? I tried comments_open($id); but it doesn't work.

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

Thanks a lot.

EDIT: i tried by specifieng it in functions.php, nothing changed.

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;
}

Upvotes: 1

Views: 2108

Answers (2)

Isaac
Isaac

Reputation: 983

The <?php comments_open( $post_id ); ?> don't open comment on a specified post ID but either return true or false depending if comments are allowed or not for this post

There is how to open comment

$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

There is how to display the comment form for the current post

<?php comment_form(); ?>

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

Upvotes: 2

Marin Atanasov
Marin Atanasov

Reputation: 3316

Go to the administration. Find the particular post, and open it to go to its Edit page. Then, from the top right portion of the screen, click "Screen Options". From there, toggle "Discussion". This will make the "Discussion" meta box appear below your post's WYSIWYG editor. There you can tick "Allow Comments", and "Allow trackbacks and pingbacks on this page."

If you want to do this programatically, you can use the following code:

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

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

Upvotes: 1

Related Questions