Home › Forums › General Issues › Adding custom fields search to WordPress search › Reply To: Adding custom fields search to WordPress search
Hi EssexPaulo,
Not sure if this is what you are after but have you tried by modifying your search.php file on your theme to something like this:
<?php
$customers = get_posts(array(
'post_type' => 'customers',
'posts_per_page' => -1,
'nopaging' => true,
'meta_query' => array(
array(
'key' => 'business_type',
'value' => '"' . get_search_query() . '"',
'compare' => 'LIKE'
)
)
));
?>
<?php /* Loop into the customers array and display the results */ ?>
<?php foreach($customers as $customer_post) : ?>
<?php /* Show your results */ ?>
<?php setup_postdata($customer_post); ?>
<?php endforeach; ?>
<?php /* Keep standard search loop for any other posts */ ?>
<?php while (have_posts()) : the_post(); ?>
<?php /* Here remains the rest of the original search.php */ ?>
<?php endwhile; ?>
Cheers,
Milton
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.