i'm having some problem creating nice 1 query to be able to get search results which includes NOT only post_type POST but also attachments. BUT if search query return attachment, i want that it won't be returned if that's attachment's parent is NOT published.
I'm using ajaxy-search plugin and i want to customize it to search what i want. I pasted query which works for me, but i want to exclude attachments which parents are not published.
$results = $wpdb->get_results(
$wpdb->prepare(
"select $wpdb->posts.ID,
$wpdb->posts.post_status,
$wpdb->posts.post_parent,
$wpdb->posts.post_type
from $wpdb->posts
where post_title like '%%%s%%' and
(post_type='albumas' OR post_mime_type='audio/mpeg')
AND (post_status = 'inherit' OR post_status = 'publish')
$excludes limit 0,".$setting->limit,
($setting->search_content == true ? array($name, $name):$name)
)
); `
I know how to do that, but i want to get the most optimal code here, not executing in loop queries to check post_parent id and then if it's published. I want as much performance friendly code as it can be :D