我正在使用WP_Query(漂亮的標準)。這一切都很好。WordPress的WP_Query搜索條件'post_name'
但是,我做了一個特殊的修改,如果用戶在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);
?>
您的幫助將不勝感激。如果我只能看到如何搜索這個特定的'slu'',那就太好了。
非常感謝, Michael。
沒關係,我想通了!我必須使用'name'而不是'post_name'。 'name'=>'rebecca-atkinson', –
http://wordpress.stackexchange.com/a/18715/22616 – softsdev