php - 如何显示在 php 中选择的特定类别的帖子?
问题描述
我正在尝试在 wordpress 中的现有插件上添加巴士公司过滤器。我已经能够从许多列表中选择一家巴士公司,但是当我按 Enter 时,会显示所有公司提供的所有巴士。我只想看到从campany中选择的公共汽车。任何帮助将不胜感激。
这是我选择巴士公司的功能
function wbtm_bus_name($name, $value = ''){
global $post;
if($post){
$values = get_post_custom( $post->ID );
}else{
$values ='';
}
$company_name = 'wbtm_bus_company';
$taxonomies = get_terms($company_name, array(
"orderby" => "count",
'hide_empty' => false,
) );
$hierarchy = _get_term_hierarchy($company_name);
if ( ! empty( $taxonomies ) && ! is_wp_error( $taxonomies ) ) : ob_start(); ?>
<select name="<?php echo $name; ?>" class='seat_type select2'>
<option value=""><?php _e('Select a company','bus-ticket-booking-with-seat-reservation')?></option>
<?php
// *************custom for form campany ****************
foreach ( $taxonomies as $taxonomie ) :
$selected = $type_name == $taxonomie->name ? 'selected' : '';
if( ! empty( $value ) ) $selected = $taxonomie->name == $value ? 'selected' : '';
printf( '<option %s value="%s">%s</option>', $selected, $taxonomie->name, $taxonomie->name );
endforeach; ?>
</select>
<?php endif;
$content = ob_get_clean();
return $content;
}
这是我的巴士搜索功能:
function wbtm_bus_search($atts, $content=null, $name){
$company = isset($_GET['bus_company_detail']) ? strip_tags($_GET['bus_company_detail']) : '';
<div class="wbtm-search-result-list">
<?php
$paged = get_query_var("paged") ? get_query_var("paged") : 1;
$meta_query_args = array(
array(
'key' => 'wbtm_bus_bp_stops',
'value' => $start,
'compare' => 'LIKE',
),
array(
'key' => 'wbtm_bus_next_stops',
'value' => $end,
'compare' => 'LIKE',
),
);
if (!empty($company)) {
$arg3 = array(
'key' => 'bus_company_detail',
'terms' => $company,
'compare' => 'IN',
'field' => 'term_id',
'value' => 'bus_company_detail',
);
array_push($meta_query_args,$arg3);
}
// print_r(meta_query_args);
$args_search = array(
'post_type' => array('wbtm_bus'),
'paged' => $paged,
'posts_per_page' => $show,
'meta_query' => array(
'relation' => 'AND',
$meta_query_args
)
);
if(!empty($bus_cat)) {
$arg4 = array(
'post_type' => array('wbtm_bus'),
'tax_query' => array(
array(
'taxonomy' => 'bus_company_detail',
'field' => 'term_id',
'terms' => $bus_cat,
),
),
);
$args_search = array_merge($args_search, $arg4);
}
}
解决方案
推荐阅读
- java - 如何在 Spring Boot 中测试调用另一个 SOAP Web 服务的 REST Web 服务
- html - 制作固定宽度和高度的html
- node.js - 部署响应到 github
- arrays - TypeScript - 防止只有接口实现的对象推送到对象类实例数组
- c++ - 在模板类的声明和定义分离的情况下防止重新定义问题
- c++ - 在 C++ 中使用 MinGW 工具包含多个类/.o 文件
- flutter - 如何将 RaisedButton 移动到屏幕的底部中心?
- javascript - 输入到输入字段的文本被复制到另一个输入字段值的状态 - 为什么?
- django - DRF 简单 jwt。如何更改 TokenObtainPairView 的响应以获取访问令牌 EXPIRES 时间
- python - numpy 从一维数组中选择多个范围