Title: Custom database select query from admin?
Last modified: August 20, 2016

---

# Custom database select query from admin?

 *  [Jess](https://wordpress.org/support/users/jessn/)
 * (@jessn)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/custom-database-select-query-from-admin/)
 * Does anyone know if this is possible? I have a custom write panel on my page 
   writing screen, and what I want to do is add a select menu with special options.
   I thought that perhaps I could use a custom database select query to look up 
   all posts in a custom post type called “Flowers”, and then echo out the titles
   as options in the select menu.
 * It’s a weird request, I know, but I’d love to figure if it can be done. Can I
   have a database query from a custom write panel?
 * I had tried this but everything died:
 *     ```
       global $wpdb, $post;
   
       $results = $wpdb->get_results("SELECT $wpdb->posts.*
       FROM $wpdb->posts, $wpdb->postmeta
       WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id
       AND $wpdb->posts.post_status = 'publish'
       AND $wpdb->posts.post_type = 'Flowers'
       ORDER BY $wpdb->posts.post_title ASC LIMIT 0, 100");
   
       if ( $results ):
       foreach ($results as $post) : setup_postdata( $post );
   
       endforeach;
       ```
   

The topic ‘Custom database select query from admin?’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [Jess](https://wordpress.org/support/users/jessn/)
 * Last activity: [14 years, 5 months ago](https://wordpress.org/support/topic/custom-database-select-query-from-admin/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
