How would I modify the following SQL Query to allow me to search multiple meta keys at once? e.g. user_business AND user_about
In the end I’ll be searching about 40 – 50 different meta keys; or if there’s an option to search ALL of them, that’d be even better.
<?php
/**
* @package WordPress
* @subpackage themename
*/
get_header(); ?>
<?php
$url = $_SERVER['REQUEST_URI'];
$tokens = explode("https://wordpress.stackexchange.com/", $url);
global $search;
$search = $tokens[sizeof($tokens)-1];
$searchQuery = str_replace("-", " ", $search);
?>
<?php echo $search; ?>
<div id="main">
<div id="primary">
<div id="content">
<?php the_post(); ?>
<div class="contentLeft">
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?> role="article">
<h1 class="entry-title">Search Results for: <?php echo $searchQuery; ?></h1>
<div class="entry-content">
<?php
global $wpdb;
$usermeta = $wpdb->prefix . 'usermeta';
// get id of user
$select_user = "SELECT user_id FROM $usermeta WHERE meta_key = 'user_business' AND meta_value LIKE '%$searchQuery%'";
$user_id = $wpdb->get_var($select_user);
echo $user_id;
?>
</div><!-- .entry-content -->
</article><!-- #post-<?php the_ID(); ?> -->
</div>
<div class="contentRight"><?php if ( dynamic_sidebar('main-sidebar') ) : else : ?><?php endif; ?></div>
</div>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_footer(); ?>