Support

Account

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.

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