Support » Fixing WordPress » 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 );
  • The topic ‘Custom database select query from admin?’ is closed to new replies.