I’m new to wordpress. I’m having trouble with a query I wrote to fetch the previous and next posts. ( I check
$sql = "
SELECT * FROM wp_posts WHERE post_date < ( SELECT post_date FROM wp_posts WHERE ID = {$id} ) LIMIT 1
UNION
SELECT * FROM wp_posts WHERE post_date > ( SELECT post_date FROM wp_posts WHERE ID = {$id} ) LIMIT 1
";
$wpdb->query($sql);
$arrPosts = $wpdb->last_result;
But I only get one post in $arrPosts. ( I know there are more than two). What’s going on?
Try:
That said, note that there also is an API to get these two. See in particular: