Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Just wondered if someone could spare 5 mins to help me understand where I might be going wrong.

I have a set of custom fields for jobs - I would like to create two drop down menus as a quick search:

Categories for example - IT, Warehousing, Sales... Salary - 20-30k

I have cobbled together this query -

 $myquery = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT meta_value, post_status FROM $wpdb->postmeta, $wpdb->posts WHERE meta_key = %s AND post_status IN ('publish') ", $metakey));

With this query, it does populate a drop down list, however, it's still including 'drafts' - in the drop down.

So, how would I exclude 'draft pages' from populating the drop down?

Many thanks

Andy

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

I think you need a join.

$myquery = $wpdb->get_col(
    $wpdb->prepare(
        "SELECT DISTINCT meta_value FROM $wpdb->postmeta
         INNER JOIN $wpdb->posts ON $wpdb->postmeta.post_id = $wpdb->posts.ID
         WHERE
             meta_key = %s AND
             post_status IN ('publish')",
        $metakey
    )
);
share|improve this answer
    
sorry for my delay, that is brilliant, thank you so much for that, it worked like a charm - I need to look into how to use JOIN! –  Andy Jul 8 '13 at 13:03
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.