Sauter la navigation

[Résolu] Add code to search multiple taxonomies

This support ticket is created Il y a 4 années et 5 mois. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Marqué : 

Ce sujet contient 19 réponses, a 2 voix.

Dernière mise à jour par davidm-13 Il y a 4 années et 4 mois.

Assisté par: Shane.

Auteur
Publications
#1744789

This is the front end where I submit parameters to the View.

<div class="container">
<div>
      <h1 class="sub-ttl sub-ttl-r">
         Search for Plants by their Medicinal Uses:
       </h1> 
       <label class="label-right" for="wpv-complaint">Complaint Treated:</label>
          [xyz-ips snippet="select-complaint"]
       <label class="label-right" for="wpv-system-state">System / State Effected:</label>
         <select name="wpv-system-state">
           <option value="" disabled selected hidden>No System / State selected</option><br/>
      [xyz-ihs snippet="select-options-system"]
      </select> 
       <label class="label-right" for="wpv-actions">Herbal Action:</label>
         <select name="wpv-actions">
           <option value="" disabled selected hidden>No Herbal Actions selected</option><br/>
         [xyz-ihs snippet="select-options-actions"]
      </select>
    <p style="font-size: 14px;">Select plants who's medicinal use includes (select an option):<br>
      a) All the selected terms <input  type="radio" name="all-any" value="All" checked><br>
      b) Any of the selected terms <input  type="radio" name="all-any" value="Any">
     </p>  
      <div>
      <button class="btn button" name="submit">Search</button>
       <button class="btn butt"> Clear Search</button>
       </div>   
    </div>
</div>

Can you please check if there's a problem here that's stopping the View running.
Thanks

#1748857

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hi David,

The the code below i've replaced the $_POST with $_GET because we can get the values from the URL. However please remember this is custom coding which is out of our support scope so my assistance here is limited. I would highly recommend hiring a developer to create this custom query for you.

//Return only posts from the current author when listing posts of type company:
add_filter( 'wpv_filter_query', 'prefix_show_only_current_author', 99,3);
  
function prefix_show_only_current_author( $query_args,$view_setting,$view_id ) {
    
if($view_id == 1111){
if(isset($_GET['submit'])) { 
    $relation = 'OR';
    if($_GET['all-any'] == 'All') {
        $relation = 'AND';
    }
    if( !empty( $_GET['wpv-system-state'] ) || 
        !empty( $_GET['wpv-complaint'])  || 
        !empty( $_GET['wpv-actions'])) {
        $query_args['tax_query'] = array(
            'relation' => $relation, 
            array(
                'taxonomy' =>  'complaint-use', 
                'field' => 'slug',
                'terms' => $_GET['wpv-complaint']
            ),
            array(
                'taxonomy' =>  'system', 
                'field' => 'slug',
                'terms' => $_GET['wpv-system-state']
            ),          
            array(
                'taxonomy' => 'action-medicinal',
                'field' => 'slug',
                'terms' => $_GET['wpv-actions'],
            )
        );
       
}
    return $query_args;
}

Please let me know if this helps.
Thanks,
Shane

#1749021

Hi Shane, Thanks for this.
I'm making progress - beginning to see output.
The posts I'm searching are custom child posts, would like to also display their parent post title in the output. Is there shortcode for doing this?
Thanks

#1749053

When I submit the search I redirect to a results page

<form action="?page_id=19218" method="get">

where I put the View shortcode:

[wpv-view name="medicinal use search"]
#1753039

My issue is resolved now. Thank you!