I'm trying to prepare WPDB by post type, meta key, and meta value
global $post;
global $wpdb;
$rid = absint($_POST["rid"]); // number
$last_id = absint($_POST["lastID"]); // post ID
$query = $wpdb->prepare(
"
SELECT ID
FROM $wpdb->posts
WHERE ID > %d
AND wp_posts.post_type = 'room'
AND wp_postmeta.meta_key = 'rid'
AND wp_postmeta.meta_value = %s
ORDER BY wp_posts.ID DESC
LIMIT 0, 1", $last_id, $rid);
$results = $wpdb->get_results( $query );
foreach ( $results as $row ) {
echo $row->ID;
}
die();
All I want to do is get the last ID that fits the criteria