• Hi All,
    I’ve got the below code.

    $querystr = "
        SELECT wposts.*
        FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
        WHERE wposts.ID = wpostmeta.post_id
        AND wpostmeta.meta_key = 'Day'
        AND wpostmeta.meta_value = '5'
        AND wposts.post_status = 'publish'
        AND wposts.post_type = 'post'
        ORDER BY wposts.post_date DESC
     ";

    The above works but I need to add meta key Month and eventually year. So to start I added month. As soon as I do, it stop working. Whats wrong with the below? Am baffled!

    $querystr = "
        SELECT wposts.*
        FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
        WHERE wposts.ID = wpostmeta.post_id
        AND wpostmeta.meta_key = 'Day'
        AND wpostmeta.meta_value = '5'
        AND wpostmeta.meta_key = 'Month'
        AND wpostmeta.meta_value = '8'
        AND wposts.post_status = 'publish'
        AND wposts.post_type = 'post'
        ORDER BY wposts.post_date DESC
     ";

    many thanks

Viewing 1 replies (of 1 total)
  • Thread Starter jarvo1980

    (@jarvo1980)

    Hi,

    After much searching, is it not possible to search posts on multiple custom fields?

    Thanks

Viewing 1 replies (of 1 total)
  • The topic ‘custom query not working when search by custom field’ is closed to new replies.