Home Forums General Issues Query custom post based on user selections Reply To: Query custom post based on user selections

  • Thanks John, I got the array working with the query and verified by replacing the variable with set values. It did in fact return the correct salesperson. But now I’m on to my other question which was how to pass the variable from basic select boxes in a form to the query and output the results. Below is the working query.

    // WP_Query arguments
    $args = array(
      'post_type' => 'sales_locator',
      'meta_query' => array(
        'relation' => 'AND',
          'key' => 'sl_country',
          'value' => '"'.$country.'"',
          'compare' => 'LIKE'
          'key' => 'sl_state',
          'value' => '"'.$state.'"',
          'compare' => 'LIKE'
          'key' => 'sl_industry',
          'value' => '"'.$industry.'"',
          'compare' => 'LIKE'
    // query
    $the_query = new WP_Query( $args );
    <?php if( $the_query->have_posts() ): ?>
    	<?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
    			<h1><?php the_field('sl_name'); ?></h1>
    			<?php the_content(); ?>
    	<?php endwhile; ?>
    <?php endif; ?>
    <?php wp_reset_query();	 // Restore global post data stomped by the_post(). ?>