1
我怎样才能创造条件,通过蛞蝓(类别名称)而不是由ID搜索代码。如何为特定类别的搜索客户创建定制解决方案(无需任何插件)?的WordPress:如何通过蛞蝓(类别名称)特定类别中搜索
解释:我想搜索的代码在这样一种方式,客户端可以特定类别中没有编辑任何代码搜索进行定制。谢谢!
我怎样才能创造条件,通过蛞蝓(类别名称)而不是由ID搜索代码。如何为特定类别的搜索客户创建定制解决方案(无需任何插件)?的WordPress:如何通过蛞蝓(类别名称)特定类别中搜索
解释:我想搜索的代码在这样一种方式,客户端可以特定类别中没有编辑任何代码搜索进行定制。谢谢!
是它仍然实际上,你应该检查this tutorial,其中一个作者给出了关于搜索功能的定制非常详细的解释。
一个用于必要的情况下,最有趣的部分:
// meta_query expects nested arrays even if you only have one query
$sm_query = new WP_Query(array('post_type' => 'accommodation', 'posts_per_page' => '-1', 'meta_query' => array(array('key' => '_sm_accommodation_city'))));
// The Loop
if ($sm_query->have_posts()) {
$cities = array();
while ($sm_query->have_posts()) {
$sm_query->the_post();
$city = get_post_meta(get_the_ID(), '_sm_accommodation_city', true);
// populate an array of all occurrences (non duplicated)
if(!in_array($city, $cities)){
$cities[] = $city;
}
}
}
} else{
echo 'No accommodations yet!';
return;
}
/* Restore original Post Data */
wp_reset_postdata();
if(count($cities) == 0){
return;
}
asort($cities);
$select_city = '<select name="city" style="width: 100%">';
$select_city .= '<option value="" selected="selected">' . __('Select city', 'smashing_plugin') . '</option>';
foreach ($cities as $city) {
$select_city .= '<option value="' . $city . '">' . $city . '</option>';
}
$select_city .= '</select>' . "\n";
reset($cities);
哦,人......这工作! – Morgari
任何想法伴侣? – Morgari