提问人:mickdeez 提问时间:11/15/2023 更新时间:11/15/2023 访问量:39
get_posts() 按类别 + 自定义选择字段
get_posts() by category + custom select fields
问:
我有两个“选择”自定义字段用于我的帖子,标题为author_1和author_2。以下是每个选择字段中的可能值。
testauthor1 : Test Author 1
testauthor2 : Test Author 2
testauthor3 : Test Author 3
每个选择都有一个值和一个标签。我希望我的 get_posts() 查询查找页面标题是当前所选值的标签的所有帖子。例如。。如果我有一个帖子,其中 author_1 = “testauthor2 : Test Author 2” 并且当前页面标题是“Test Author 2”,则应返回该帖子。
目前,我的查询只是返回类别 9 中的所有帖子,但它不会仅返回 author_1 或 author_2 等于当前页面标题的帖子。
function hide_cotw_heading(){
$title = get_the_title();
$args = array(
'cat' => 9,
'meta_query' => array(
'relation' => 'OR',
array(
'meta_key' => 'author_1',
'meta_label' => $title
),
array(
'meta_key' => 'author_2',
'meta_label' => $title
)
)
);
$latest_posts = get_posts( $args );
if($latest_posts){
return print_r($latest_posts);
} else{
return 'No posts';
}
}
答: 暂无答案
评论
key
value
meta_key
meta_label
meta_key
meta_query
meta_label
key
value
meta_key
author_1/2
testauthor3 : Test Author 3
label
'compare' => 'LIKE'