search-html-css-js-php
---------------------
// Shortcode for search bar
add_shortcode( 'search_bar', 'search_bar_shortcode' );
function search_bar_shortcode() {
ob_start();
?>
-1,
's' => $keyword,
'post_type' => array('page', 'post', 'company_details'),
'tax_query' => array(
'relation' => 'AND', // Ensure both conditions are met
),
);
if (!empty($selected_category)) {
$args['tax_query'][] = array(
'taxonomy' => 'categories',
'field' => 'slug',
'terms' => $selected_category,
);
}
if (!empty($selected_location)) {
$args['tax_query'][] = array(
'taxonomy' => 'location',
'field' => 'slug',
'terms' => $selected_location,
);
}
$the_query = new WP_Query($args);
if ($the_query->have_posts()) {
echo '';
while ($the_query->have_posts()) : $the_query->the_post(); ?>
';
wp_reset_postdata();
}
die();
}