This should hopefully help you on your way, although I’ve not fully tested it…
The basic search form here which will load the site_url()
with appended search query string. You should change this to better reflect your site layout such as <?php site_url( 'search' ); ?>
(‘http://website.com/search‘).
Place the Results page code within the results page template (based on the site_url() code above). This will collect all parts (inputs), turn them into a string, then use them in a custom query using the meta_query
parameter.
It’s basically saying “Find all products where gc_number equals the search string”. You can then loop through all results and output whatever you need.
If it’s not quite what you’re after, or you need a hand, drop a comment below.
<form role="search" method="get" id="acf-search" action="<?php site_url(); ?>">
...
<input type="text" name="part1" />
<input type="text" name="part2" />
<input type="text" name="part3" />
<input type="submit" value="Search" />
</form>
<?php
// Results page
// Might be worth checking to make sure these exist before doing the query.
$part_1 = $_GET['part1'];
$part_2 = $_GET['part2'];
$part_3 = $_GET['part3'];
$search_string = $part_1 . '-' . $part_2 . '-' . $part_3;
// Get all product categories
$categories = get_terms( 'product_cat' );
$counter = 0;
// Loop through categories
foreach ( $categories as $category ) {
// Get custom field
$gc_number = get_field( 'gc_number', $category );
// If field matches search string, echo name
if ( $gc_number == $search_string ) {
// Update counter for use later
$counter++;
echo $category->name;
}
}
// $counter only increases if custom field matches $search_string.
// If still 0 at this point, no matches were found.
if ( $counter == 0 ) {
echo 'Sorry, no results found';
}
?>