[英]wp_query - show all authors at selected category who wrote Posts for this category
我需要您的幫助,我是wp_query
的新手,我不知道如何顯示選定類別中為該類別撰寫帖子的所有作者。 所以這意味着我在我的頁面上例如:愛好然后我想顯示所有具有此類別的帖子以及撰寫此帖子的作者。
我搜索了很多,發現了類似的東西,但不是我需要的>_> https://wordpress.stackexchange.com/questions/134347/how-to-query-posts-from-specific-authors-and-categories -using-wp-query
希望我的意思很清楚?
希望你能幫助我:)
編輯:
啊好的謝謝! 我在我的代碼上嘗試了代碼,但我的網站上沒有任何反應:,D
我怎么了? :/
<?php
$get_cat_id = get_the_category();
$args = array(
'paged' => $paged,
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'id',
'terms' => array ( $get_cat_id),
)
)
);
$the_query = new WP_Query($args);
//the loop
$firstEntry = true;
if ( $the_query -> have_posts() ) {
while ( $the_query -> have_posts() ) {
echo $firstEntry ? '<article class="active">' : '<article>';
$firstEntry = false;
$the_query -> the_post();
$last = get_the_author_meta('last_name');
$first = get_the_author_meta('first_name');
echo '<h3 class="author"><a href="'. get_the_author_meta('display_name') . '">' . $first . " " . $last . '</a></h3>';
echo '<img src="<?php echo $template_uri; ?>/img/author_mini.jpg" alt="THOMAS SCHRÖDER" class="thumb-round">';
echo '</article>';
}
} else {
// no posts found
}
?>
編輯2:
好吧,對不起,我的英語不好,你真的不明白我的意思:/我不知道如何更好地解釋我的問題:(
我調試了 arr $the_query,這是它的一些輸出
object(WP_Query)[2458]
public 'query' =>
array (size=1)
'tax_query' =>
array (size=1)
0 =>
array (size=3)
...
public 'query_vars' =>
array (size=62)
'tax_query' =>
array (size=1)
0 =>
array (size=3)
...
'error' => string '' (length=0)
'm' => string '' (length=0)
'p' => int 0
'post_parent' => string '' (length=0)
'subpost' => string '' (length=0)
'subpost_id' => string '' (length=0)
'attachment' => string '' (length=0)
'attachment_id' => int 0
'name' => string '' (length=0)
'static' => string '' (length=0)
'pagename' => string '' (length=0)
'page_id' => int 0
'second' => string '' (length=0)
'minute' => string '' (length=0)
'hour' => string '' (length=0)
'day' => int 0
'monthnum' => int 0
'year' => int 0
'w' => int 0
'category_name' => string 'allgemein' (length=9)
'tag' => string '' (length=0)
'cat' => int 1
'tag_id' => string '' (length=0)
'author' => string '' (length=0)
'author_name' => string '' (length=0)
'feed' => string '' (length=0)
'tb' => string '' (length=0)
'paged' => int 0
'comments_popup' => string '' (length=0)
'meta_key' => string '' (length=0)
'meta_value' => string '' (length=0)
'preview' => string '' (length=0)
's' => string '' (length=0)
'sentence' => string '' (length=0)
'fields' => string '' (length=0)
'menu_order' => string '' (length=0)
'category__in' =>
array (size=0)
您需要進行自定義WP query
。
分解一下:
所以
$get_cat_id = get_the_category();
$query = new wp_query($arr);
$arr = array(
'paged' => $paged,
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'id',
'terms' => array ( $get_cat_id),
)
)
);
然后在category
foreach
post
get_the_author_id();
或類似的東西。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.