我最终的做法如下:
因为它是在post_status_transition
, 每个日志都可以有效地链接到特定的帖子。因此,我可以使用add/update\\u post\\u meta将响应和时间戳存储为该帖子的元字段。
要检索所有日志,我只需执行以下操作:
$logs = array();
$query_args = array(
\'meta_key\' => \'myresponsetimestamp\',
\'meta_compare\' => \'EXISTS\',
\'order\' => \'DESC\',
\'orderby\' => \'meta_value_num\'
);
$query = new WP_Query($query_args);
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
$post_id = get_the_ID();
$logs[] = array(
\'postid\' =>$post_id,
\'time\' => get_post_meta( $post_id, \'myresponsetimestamp\', true ),
\'response\' =>get_post_meta( $post_id, \'myresponse\', true )
);
}
}
wp_reset_postdata();