Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php $comments = $this->load_post_comments(); ?>
<?php foreach ( $comments as $comment ) { ?>
<label for="acme-comment-status-<?php echo $comment->comment_ID ?>">
<input type="checkbox" name="acme-comment-status[<?php echo $comment->comment_ID ?>]" id="acme-comment-status-<?php echo $comment->comment_ID ?>" />
This comment has received a reply.
</label>
<p>
<em><?php echo $comment->comment_author; ?></em>:
<?php echo $comment->comment_content; ?>
</p>
<?php } ?>
<?php
add_action( 'save_post', 'acme_comment_status_save_post' );
/**
* @param int $post_id The ID of the post that's currently being edited.
*/
function acme_comment_status_save_post( $post_id ) {
/* Code to verify that the user has permission to save the post has been removed
* for brevity.
*/
// If there are any values saved in the 'Published' input, save them
if ( ! empty( $_POST['acme-comment-status'] ) ) {
/* Additional sanitization should occur here before actually saving the array. */
update_post_meta( $post_id, 'acme-comment-status', $_POST['acme-comment-status'] );
}
/* Code for deleting the post value has been removed for brevity. */
}
<?php $comments = $this->load_post_comments(); ?>
<?php foreach ( $comments as $comment ) { ?>
<?php
// Retrieve the comments and determine if the ID of the current comment exists in the array
$comments = get_post_meta( get_the_ID(), 'authors-commentary-comments', true );
$is_checked = array_key_exists( $comment->comment_ID, $comments ) ? 'checked="checked"' : '';
?>
<label for="acme-comment-status-<?php echo $comment->comment_ID ?>">
<input type="checkbox" name="acme-comment-status[<?php echo $comment->comment_ID ?>]" id="acme-comment-status-<?php echo $comment->comment_ID ?>" <?php echo $is_checked; ?> />
This comment has received a reply.
</label>
<p>
<em><?php echo $comment->comment_author; ?></em>:
<?php echo $comment->comment_content; ?>
</p>
<?php } ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.