Custom database select query from admin? (1 post)

  1. jessn
    Posted 4 years ago #

    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 );

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.