Im trying to write a query that will find and display all of my posts that have the same custom field values as my input.
In wordpress I have the following…
My query is…
$pageposts = $wpdb->get_results("SELECT wposts.* FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_value = 'petrol' OR wpostmeta.meta_value = 'local' ORDER BY wpostmeta.meta_value DESC", OBJECT);
If I remove ‘OR wpostmeta.meta_value = ‘local’ This works correctly and pulls the correct post with the custom field value as ‘petrol’
Can anybody give me an idea on where im going wrong? At the moment its display all of my posts even those that are drafts and have been deleted and its also looping and displaying them numerous times…
Try:
Figured it out…