有些wordpress文章有很多修订,我知道如何列出所有的修订,使用代码:wp_list_post_revisions( int|WP_Post $post_id, string $type = 'all' )
。
然而,如何只列出文章中每一修订本的作者,则需要满足:
非常感谢!
发布于 2020-12-30 03:56:33
Use可以在此功能下面使用,以获得作者详细信息中的所有修订版和选中的副本。
根据你的需要。
function get_all_revisions($post_id){
//get all revisions of particular Page Id & Post Id
$revision = wp_get_post_revisions($post_id);
$post_author_id = array();
foreach ($revision as $key => $value) {
// Check Id Already Exists in Array
if ( ! in_array($value->post_author, $post_author_id)) {
// Store Author Id
$post_author_id[] = $value->post_author;
$get_author['author_link'] = get_author_posts_url($value->post_author); // Author Link
$get_author['author_name'] = get_the_author_meta( 'display_name', $value->post_author ); // Author Display Name
//Store All Author Details in Array
$get_author_group[] = $get_author;
}
}
return $get_author_group;
}
用法:
// 2 is page or post id
$all_revisions = get_all_revisions(2);
//print_r($all_revisions);
foreach ($all_revisions as $key => $value) {
echo $value['author_link'].'
';
echo $value['author_name'].'
';
}
发布于 2020-12-29 21:22:39
我不认为您可以通过使用任何默认函数来获得它,但是可以肯定您可以使用自定义SQL。
global $wpdb;
$post_id = get_the_ID();
$revisions = $wpdb->get_results( "SELECT pt.post_author FROM $wpdb->posts pt WHERE 1=1 AND pt.post_parent = '$post_id' AND pt.post_type = 'revision' AND pt.post_status = 'inherit' GROUP BY post_author ORDER BY pt.post_author ASC" );
https://wordpress.stackexchange.com/questions/380612
复制相似问题