Support

Account

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