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(). ?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.