我正在使用 WP_Query (非常标准)。一切都很好。
但是,我需要进行一项特定的修改,如果用户在 URL 中输入特定的帖子名称,则搜索将仅返回与该 post_name 值匹配的帖子。
请参阅下面的代码,其中包含有关特定行不起作用的注释。
<?php
$getPeople = array(
'post_type' => 'person',
'posts_per_page' => -1,
// I want this below to only return me the post with this specific value.
// This doesn't error, but doesn't work either.
// I know it seems counter-productive to a 'search' but this particular case requires it.
// This has a hard-coded value at the moment.
'post_name' => 'rebecca-atkinson',
'orderby' => 'meta_value',
'meta_key' => 'last-name',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'gender',
'value' => $theGender,
)
),
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'accent',
'field' => 'slug',
'terms' => $theAccent,
'operator' => 'IN',
),
array(
'taxonomy' => 'style',
'field' => 'slug',
'terms' => $theStyle,
'operator' => 'IN',
),
array(
'taxonomy' => 'age',
'field' => 'slug',
'terms' => $theAge,
'operator' => 'IN',
),
)
);
$myposts = new WP_Query($getPeople);
?>
我们将非常感谢您的帮助。如果我能看到如何搜索这个特定的“slug”,那就太好了。
非常感谢,
迈克尔.