我在我们的网页上使用了联合作者plus插件,因为有时我们有更多的文章作者。直到今天,它都运转得很好。我用的是经典档案。php根据全局设置列出作者的所有帖子(相同的帖子摘录、拇指、第6页的帖子–在全局WordPress和主题PHPs中定义)。我的作者要求创建主题简介页面,其中包含基于author.php
. 所以我被迫用新的WP_Query
这就是合著者插件的问题。
当我使用下面的代码时,帖子只列在指定为主要作者的作者下面,而不列在合著者下面。
<?php
$the_query = new WP_Query(
array(
\'posts_per_page\' => -1,
\'author\' => get_the_author_meta(\'ID\'),
)
);
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();
the_time(\'d.m.Y \');
the_permalink();
the_title();
endwhile;
wp_reset_postdata();
else :
_e( \'Sorry, no posts matched your criteria.\' );
我试着根据
taxonomy
,
author_name
,
coauthor_meta
, 等等,没有任何帮助。
您可以看到示例here (抱歉,这不是英文):这篇文章没有列在两位作者下面。
SO网友:Jan Hanzman Kohoutek
没关系,我通过更改author\\u name而不是IDWorks的查询来修复它!
$the_query = new WP_Query(
array(
\'posts_per_page\' => -1,
\'author_name\' => get_the_author_meta(\'nickname\'),
)
);
我们可以结束这个问题!
SO网友:Alex DS
但是如果您想使用合著者列表来查询插件中的帖子,则必须使用
get_the_author_meta( \'user_nicename\', get_current_user_id() );
$locations = new WP_Query(array(
\'post_type\' => \'location\',
\'posts_per_page\' => -1,
\'author_name\' => get_the_author_meta(\'user_nicename\', get_current_user_id()) //FILTER POSTS BY CO-AUTHORS (Co-Author-Plus Plugin)
));
SO网友:Apurba Podder
/**
* @param $id
* @param int $paged (if $paged = null returl all posts)
* @return array|bool
*/
function get_coauthor_posts_by_author_id($id, $paged = 1)
{
global $wpdb;
$slug = \'cap-\' . strtolower(get_userdata($id)->user_nicename);
$max_post = get_option(\'posts_per_page\');
$post_lower_limit = 0;
if ($paged > 1) {
$post_upper_limit = $max_post * $paged;
$post_lower_limit = $post_upper_limit - $max_post;
}
$term_id = $wpdb->get_results($wpdb->prepare("SELECT term_id FROM $wpdb->terms WHERE slug = %s ", $slug))[0]->term_id;
$sql = "SELECT SQL_CALC_FOUND_ROWS $wpdb->posts.id FROM $wpdb->posts LEFT JOIN $wpdb->term_relationships AS tr1 ON ($wpdb->posts.id = tr1.object_id) LEFT JOIN $wpdb->term_taxonomy ON ( tr1.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id ) WHERE 1=1 AND (($wpdb->posts.post_author = %d OR ($wpdb->term_taxonomy.taxonomy = \'author\' AND $wpdb->term_taxonomy.term_id = %d))) AND $wpdb->posts.post_type = \'post\' AND ($wpdb->posts.post_status = \'publish\' OR $wpdb->posts.post_status = \'private\') GROUP BY $wpdb->posts.id ORDER BY $wpdb->posts.post_date DESC";
$sql_limit = " LIMIT %d, %d";
if ($paged !== null) {
$sql = $sql . $sql_limit;
}
if ($term_id !== null) {
$result = $wpdb->get_results($wpdb->prepare($sql, $id, $term_id, $post_lower_limit, $max_post), ARRAY_A);
return array_column($result, \'id\');
}
return false;
}