[英]Get the author's posts in spacific category
我想在空间类别中获取作者的帖子并将其显示在作者页面中我尝试了此代码但它不起作用,有什么问题? 我的代码:
<?php
$url= get_site_url();
$author_id = get_the_author_meta('ID');
$args = array(
'author' => $author_id,
'tax_query' => array(
'relation' => 'AND',
array(
'cat' => '161,181,157',
'post_count' => '3',
),
),
);
$query = new WP_Query( $args );
while ( $query->have_posts() ) {
$query->the_post();
$postid = get_the_ID();
echo '<a href='. $url .'?p='. $postid .'>' . get_the_title() . '</a>';
}
?>
试试下面的代码。
$url = get_site_url();
$author_id = get_the_author_meta('ID');
$args = array(
'author' => $author_id,
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'term_id',
'terms' => array(161,181,157)
),
),
);
$query = new WP_Query( $args );
while ( $query->have_posts() ) {
$query->the_post();
$postid = get_the_ID();
echo '<a href='. $url .'?p='. $postid .'>' . get_the_title() . '</a>';
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.