I have developed a custom search form for searching for a term in the ‘postmeta’ table and then returning an array of post id’s that match that data.
I want to then get the WP post objects for each of the returned post id’s in the array and run them through a loop to display the content on a custom page template.
I am able to do this with a PHP foreach loop and echo individual bits of data. Here is the function I have built to test the functionality I talking about.
function sales_search_data() {
global $wpdb;
$streets = $wpdb->get_results(
"
SELECT post_id
FROM $wpdb->postmeta
WHERE (meta_key = 'street' OR meta_key = 'suburb' OR meta_key = 'city' OR meta_key = 'zip')
AND meta_value = '" . mysql_escape_string($_POST['street_search']) . "'
");
foreach ( $streets as $street ) {
echo $street->post_id;
}
}
The $_POST[‘street_search’] is user input. And as I mentioned the query is working ok I just can’t figure out how to get the Post Object into a loop from an array of Post Id’s.
Thanks for your help.