Displaying Posts Using a Custom Select Query showing wrong title
-
I have created a function as follows:
function get_post_by_custom_field($day) { global $wpdb; $querystr = " SELECT wposts.* FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_key = 'day' AND wpostmeta.meta_value = '" . $day . "' AND wposts.post_status = 'publish' AND wposts.post_type = 'post' ORDER BY wposts.post_date DESC "; $pageposts = $wpdb->get_results($querystr, OBJECT); if ($pageposts): foreach ($pageposts as $post): global $post; setup_postdata($post); //Echo the output the_title(); echo '<br />'; endforeach; endif; }
Is was taken from the page:
https://codex.www.ads-software.com/Displaying_Posts_Using_a_Custom_Select_Query
The problem I have is the_title() that is returned are not the title’s of the results – however it is returning the correct ammount of results.
Any help please?
- The topic ‘Displaying Posts Using a Custom Select Query showing wrong title’ is closed to new replies.