I'm trying to make a short code to pull out phone numbers from my posts. I read this http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query and it didn't work with me.
This is my code and it's at the top of my header template file.
<?php function getPhoneBook(){
$querystr = "
SELECT kposts.* , kpostmeta.*
FROM $wpdb->posts kposts, $wpdb->postmeta kpostmeta
WHERE kposts.ID = kpostmeta.post_id
AND kpostmeta.meta_key = 'Telephone'
AND kposts.post_type = 'post'
ORDER BY kposts.post_date DESC
";
echo $querystr;
$result = mysql_query($querystr) or die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
echo $row["post_title"];
echo $row["meta_value"];
}
}
add_shortcode('phoneBook', 'getPhoneBook');
?>
I only get 4 resutls, even though there are over 200 results. If I run the SQL question using phpMyAdmin, I get the desired results. So what's up with the wordpress template???!