I have a small problem with the functioning of a search bar that gives the user the possibility to find professionals based on their job categories.
I explain: I am talking about a portal that allows the user to be able to carry out a search as written above.
How I managed the programming: if it is a portal where there are professionals, I created the custom post type: Pro
To specify the services that these professionals are able to perform, I created a plugin that allows me by specifying in the array which custom post types to grant the possibility to implement taxonomies:
register_taxonomy( 'categoria', array( 'pro' ), $ args );
now very simply I have implemented a form on a page:
<div id="search_video" class="container-fluid"> <div style="text-align: center;background-color: #fff;" class="col-md-12"> <form name="NOME_FORM" method="get" id="advanced-searchform" role="search" action="<?php echo esc_url( home_url( '/results' ) ); ?>"> <div class="input-group mb-3"> <div class="input-group-prepend"> <span class="input-group-text"><i class="fa fa-search"></i></span> </div> <input type="text" id="art" name="art" class="form-control"> </div> </form> </div> </div> </div>
pointing to the results page.
to display the results I used this query:
<?php $ art_p = $ _GET['art']; $ query_v = array( 'post_type' => array('pro'), 'posts_per_page' => -1, 'orderby' => 'meta_value', 'order' => 'ASC', 'tax_query' => array( array( 'taxonomy' => 'categoria', 'terms' => $ art_p, ) ) ); $ res_v = new WP_Query( $ query_v ); ?>
now the problem:
I have implemented two test professional profiles, in the services category, I have specified as a sub-category of services for professional A:
- creation of websites
and for professional B:
- logo creation
but if I look in the website creation bar: it gives me both professionals as a result and this is not good.
So my question is how can I filter the results so that the user search is based on the sub-category of services and only brings out the professionals who own that sub-category, what did I do wrong with my query?