Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

1

332
Views
WordPress ajax filtra publicaciones combinando múltiples taxonomías

Estoy trabajando en un filtro para una cuadrícula de publicaciones en Wordpress con ajax.

Básicamente funciona como un todo, pero estoy tratando de filtrar usando múltiples taxonomías. Pero en lugar de combinar las taxonomías para refinar la búsqueda, como publicaciones etiquetadas con 'a' Y 'b'

Solo muestra todas las publicaciones con la etiqueta 'a' y con la etiqueta 'b'

 $args = array( 'post_type' => 'projects', 'orderby' => 'date', // we will sort posts by date 'order' => $_POST['date'] // ASC or DESC ); if( isset($_POST['multi_subject']) && !empty($_POST['multi_subject']) ) { $args['tax_query'] = array( array( 'taxonomy' => 'category', 'field' => 'id', 'terms' => $_POST['multi_subject'] ) ); } if( isset($_POST['multi_style']) && !empty($_POST['multi_style']) ) { $args['tax_query'] = array( array( 'taxonomy' => 'styles', 'field' => 'id', 'terms' => $_POST['multi_style'] ) ); } $query = new WP_Query( $args ); if( $query->have_posts() ) : while( $query->have_posts() ): $query->the_post(); echo '<a href="'. get_permalink() .'" data-author="'. get_the_author() .'" data-tier="'. get_author_role() .'">'; echo '<h2>' . $query->post->post_title . '</h2>'; echo '<div>'. the_post_thumbnail() .'</div>'; echo '</a>'; endwhile; wp_reset_postdata(); else : echo 'No posts found'; endif; die();

Estoy seguro de que es algo simple de hacer con el isset y luego establecer los argumentos, pero no puedo resolverlo.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Su consulta de impuestos actual no permite verificar ambas taxonomías porque si ambas están configuradas, su segunda verificación de impuestos anulará la primera. Para permitir ambos, debe agregarlos ... refactorice su tax_query a algo como esto:

 // start with an empty array $args['tax_query'] = array(); // check for first taxonomy if( isset($_POST['multi_subject']) && !empty($_POST['multi_subject']) ) { // append to the tax array $args['tax_query'][] = array( 'taxonomy' => 'category', 'field' => 'id', 'terms' => $_POST['multi_subject'] ); } // check for another taxonomy if( isset($_POST['multi_style']) && !empty($_POST['multi_style']) ) { // append to the tax array $args['tax_query'][] = array( 'taxonomy' => 'styles', 'field' => 'id', 'terms' => $_POST['multi_style'] ); }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!