我向注释表单中添加了一些输入字段,然后这些新数据存储在commentmeta表中。删除评论后,commentmeta上的数据仍然存在。
删除评论时,如何删除这些数据?(我需要一个类似于delete\\u帖子的操作,但用于评论……它是否存在?)
我向注释表单中添加了一些输入字段,然后这些新数据存储在commentmeta表中。删除评论后,commentmeta上的数据仍然存在。
删除评论时,如何删除这些数据?(我需要一个类似于delete\\u帖子的操作,但用于评论……它是否存在?)
查看函数wp_delete_comment()
. 它会在删除注释之前触发操作:
/**
* Fires immediately before a comment is deleted from the database.
*
* @since 1.2.0
*
* @param int $comment_id The comment ID.
*/
do_action( \'delete_comment\', $comment_id );
…和删除后的一个:/**
* Fires immediately after a comment is deleted from the database.
*
* @since 2.9.0
*
* @param int $comment_id The comment ID.
*/
do_action( \'deleted_comment\', $comment_id );
因此,您可以将回调绑定到:add_action( \'deleted_comment\', function( $comment_id ) {
delete_comment_meta( $comment_id, \'your_meta_key\' );
} );
我想使用模板标记显示帖子上的评论数 <?php comments_number( $zero, $one, $more ); ?> 但是,由于某些原因,此标记不起任何作用,也不会打印到页面上。你可以看看我在http://blog.diginomics.com/bitcoins-innate-regulation/以下是3个模板标记的完整代码片段:author、category和comment: <div class=\