Tell us what you are trying to do?
- I want to achieve filter view in PHP function not with toolset other tools because of some restrictions. I've added a function in funtion.php and displaying it on front end.
- First, I want to merge $category_name_array with $andrew_query so that I should not duplicate the query on one page. I wanted to have dropdown option by just one query.
- Second, Why I used two variables $ category_name_array is for showing the post category on front end in dropdown and $andrew_query is showing all the post in post_type =>'team'.
- Third, their will be 2 drop-downs in front end one for filtering from dropdown added in the backend with custom fields. And other is category in the backend that will work same as first dropdown at front end.
- Forth, Both dropdowns work with the combination. ] if one is selected 2nd will change accordingly.
Is there a similar example that we can see?
- https://toolset.com/forums/topic/show-custom-field-in-filter-dropdowns/
- https://toolset.com/forums/topic/filter-view-via-drop-taxonomy/
What is the link to your site?
- Please provide me hidden link so I can upload the link.
My function:
function team_shortcode( $atts ) {
extract( shortcode_atts( array(
'type' => 'team',
), $atts ) );
$args = array(
'post_type' => 'team',
'post_status' => 'publish',
//'posts_per_page' => 100,
'taxonomy' => 'team-category',
'hide_empty' => 0
);
$output="";
$andrew_query = new WP_Query( $args );
//$output.=print_r($andrew_query).'<br><br><br>';
$category_name_array = get_categories(array('type' => 'team', 'post_status' => 'publish', 'taxonomy' => 'team-category', 'hide_empty' => 0));
//$output.='<br><br><br>'.print_r($category_name_array);
$output .= '<select>';
foreach(($category_name_array) as $category){
$catergory_name_related=$category->name;
$output .= '<option>'.$category->name.'</option>';
}
$output .= '</select>';
$output .= '<select>';
// foreach(($category_name_array) as $category){
// $catergory_name_related=$category->name;
$output .= '<option>'.types_render_field( 'country' ).'</option>';
// }
$output .= '</select>';
while ( $andrew_query->have_posts() ) : $andrew_query->the_post();
$post_id=get_the_ID();
$field = get_permalink($post_id);
$output.='<div class="wpb_column vc_column_container vc_col-sm-3">';
$output.='<div class="vc_column-inner">';
$output.='<div class="wpb_wrapper">';
$output.='<div class="mega_team_case">';
$output.='<div class="mega_team_wrap">';
$output.='<div class="member-image">';
$output.='';
$output.='</div>';
$output.='<div class="member-name">'.get_the_title().'<span style="background-color: #27BEBE;">'.types_render_field( 'designation' ).'</span></div>';
$output.='</div>';
$output.='</div>';
$output.='</div>';
$output.='</div>';
$output.='</div>';
endwhile;
wp_reset_query();
return $output;
}
add_shortcode('team', 'team_shortcode');