Wordpress:WP_Query搜索条件'post_name' [英] Wordpress: WP_Query search criteria on 'post_name'
问题描述
我使用WP_Query(很标准)。一切都很好。
I'm using WP_Query (pretty standard). It all works great.
但是,我有一个特殊的修改,其中,如果用户在URL中输入特定的帖子名称,搜索将只返回
However, I have a particular modification to make, where, if the user enters the specific post name in the URL, the search will return only the post that matches that post_name value.
请参阅下面的代码,并注明该特定行不起作用。
See my code below with a comment about the particular line not working.
<?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);
?>
您的帮助将非常感谢。如果我只能看到如何搜索这个特定的lug子,那将是伟大的。
Your help would be greatly appreciated. If I could just see how to search on this specific 'slug' then that would be great.
非常感谢,
Michael。
Many thanks, Michael.
推荐答案
除了我在上面的评论中的答案,我想我也会把它作为官方回答:
In addition to my answer in the comments above, I thought I'd post it as an official answer too:
我必须使用'name'
和 NOT 'post_name'
。
例如:
'name' => 'rebecca-atkinson'
希望这有助于未来。
这篇关于Wordpress:WP_Query搜索条件'post_name'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!