php - 获取作者在空间分类中的帖子
问题描述
我想在特定类别中获取作者的帖子并将其显示在作者页面中我尝试了此代码但它不起作用,这是什么问题?我的代码:
<?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>';
}
推荐阅读
- arrays - jq 处理 JSON 数组作为输入以在 while 循环内解析 JSON 数组的元素
- java - opencv的jar异常
- android - 删除 Firebase 用户并返回登录
- python - 如何通过单击一个按钮使pyqt调用两种方法
- c# - Unity Facebook 登录在 Unity 的发布模式下不起作用
- php - Laravel/PHP 如何使用数组映射和排序
- python - 交错一个numpy矩阵的行,生成置换方案
- ios - 2018 年在 Objective-C 中向 NSURL 添加查询字符串的方法
- vue.js - 使用计算属性 vuejs 进行高级搜索
- database - 为池创建连接时收到异常。IO 错误:weblogic 服务器中指定的未知主机