• Hi all

    Am trying to query multiple meta_keys & meta_values, but not getting the query right.

    $queryall = "SELECT DISTINCT(post_id) FROM wp_postmeta WHERE (meta_key = 'mb_category' AND meta_value = 'To Let') ORDER BY post_id DESC";

    $queryall = "SELECT DISTINCT(post_id) FROM wp_postmeta WHERE (meta_key = 'mb_property-type' AND meta_value = 'id119') ORDER BY post_id DESC";

    Need to combine the two queries.
    Do i need to do an inner join or left join… Can someone please assist or advise?

    Regards,
    Charl

Viewing 1 replies (of 1 total)
  • From the codex ( using built-in functions ), modified to your needs I think.

    $args = array(
    	'post_type' => 'post',
    	'meta_query' => array(
    		array(
    			'key' => 'mb_category',
    			'value' => 'To Let',
    			'compare' => '='
    		),
    		array(
    			'key' => 'mb_property-type',
    			'value' => 'id119',
    			'compare' => '='
    		)
    	)
    );
    $query = new WP_Query( $args );

    Why do this with plain SQL?

Viewing 1 replies (of 1 total)
  • The topic ‘Custom WP query on multiple meta_keys and meta_values’ is closed to new replies.