Title: Short Code MySQL
Last modified: August 19, 2016

---

# Short Code MySQL

 *  Resolved [thepaperdump](https://wordpress.org/support/users/thepaperdump/)
 * (@thepaperdump)
 * [17 years, 6 months ago](https://wordpress.org/support/topic/short-code-mysql/)
 * 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](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???!

Viewing 1 replies (of 1 total)

 *  Thread Starter [thepaperdump](https://wordpress.org/support/users/thepaperdump/)
 * (@thepaperdump)
 * [17 years, 6 months ago](https://wordpress.org/support/topic/short-code-mysql/#post-877908)
 * nevermind, got it working. I forgot I was using the dev. database that had different
   into.

Viewing 1 replies (of 1 total)

The topic ‘Short Code MySQL’ is closed to new replies.

## Tags

 * [custom fields](https://wordpress.org/support/topic-tag/custom-fields/)
 * [MySQL](https://wordpress.org/support/topic-tag/mysql/)

 * 1 reply
 * 1 participant
 * Last reply from: [thepaperdump](https://wordpress.org/support/users/thepaperdump/)
 * Last activity: [17 years, 6 months ago](https://wordpress.org/support/topic/short-code-mysql/#post-877908)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
