0

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

1 Answer 1

0

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
    )
);
1
  • 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, 2013 at 13:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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