Quantcast
Channel: Topic Tag: MySQL | WordPress.org
Viewing all articles
Browse latest Browse all 5527

vtxyzzy on "Can't get a WP query working"

$
0
0

I think you can use filters to do what you want. First, add these two filters to your functions.php:

function mam_posts_join ($join) {
   global $mam_global_join;
   if ($mam_global_join) $join .= " $mam_global_join";
   return $join;
}
function mam_posts_where ($where) {
   global $mam_global_where;
   if ($mam_global_where) $where .= " $mam_global_where";
   return $where;
}
add_filter('posts_join','mam_posts_join');
add_filter('posts_where','mam_posts_where');

Then, use the code below to create the $args array for your query:

if ($_POST['achternaam'] != '') { $this->input_name = $_POST['achternaam']; }
if ($_POST['provincie'] != '' && $_POST['provincie'] != 'Alle provincies') { $meta_query[] = array('key' => 'provincie', 'value' => $_POST['provincie'], 'compare' => 'LIKE'); }
if ($_POST['plaats'] != '') {
   $meta_query['relation'] = 'OR';
   $meta_query[] = array('key' => 'city', 'value' => $_POST['plaats'], 'compare' => 'LIKE');
   $meta_query[] = array('key' => 'city2', 'value' => $_POST['plaats'], 'compare' => 'LIKE');
}
if ($_POST['modaliteit'] != '') {
   $mam_global_join = " JOIN $wpdb->postmeta pm3 ON (pm3.post_id = $wpdb->posts.ID)";
   $mam_global_where = " AND pm3.meta_key = 'modality' AND pm3.meta_value = '{$_POST['modaliteit']}'";
}

$args = array(
    'role'            => 'Therapeut',
    'posts_per_page'  => 1000,
    'exclude'         => array(1),
    'meta_query'      => $meta_query
);

Viewing all articles
Browse latest Browse all 5527

Trending Articles