I have a site that is setup with Pages and posts. I have a custom field in the posts that has the numerical value (e.g., 297) of the Page entered depending on the hotel that I need to retrieve the posts for (the posts are specials that are running for that hotel).
I need to be able to pass a variable to the wpostmeta.meta_value in the page template used just for the specials.
Explanation: I have a Page template called “Special Promotions” and each hotel has its own subpage for their promotions.
The reasoning behind the various promotions is that someone can select just the type of promotion in case they are looking for Romantic, Ski, Family, etc.
You do need to add a custom field to the posts (mine is special_locations with the page # entered in the value field.
$thehotel = $post->ID;
$querystr = “
FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
WHERE wposts.ID = wpostmeta.post_id
AND wpostmeta.meta_key = ‘special_location’
AND wpostmeta.meta_value = ‘$thehotel’
AND wposts.post_status = ‘publish’
AND wposts.post_type = ‘post’
AND wposts.post_date < NOW()
ORDER BY wposts.post_date DESC