Support » Fixing WordPress » How to get post id on certain meta data values

Viewing 2 replies - 1 through 2 (of 2 total)
  • Figured it out myself

    global $wpdb;
    		$querystr = "SELECT post_id, count(post_id)
    			FROM $wpdb->postmeta
    			WHERE
    				(meta_key = 'product_aid' AND meta_value = '". $aid ."') OR
    				(meta_key = 'product_id' AND meta_value = '". (string)$item->productID ."')
    			GROUP BY post_id
    			HAVING count(post_id) = 2;
    		";
    		$postid = $wpdb->get_var($wpdb->prepare($querystr));

    Worked like a charm. Thanks for sharing this!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to get post id on certain meta data values’ is closed to new replies.