• I have this query below, selecting data based on meta fields. It returns nothing in WordPress. If I run the same query in MyPHPAdmin, it works as expected.

    This line is giving me trouble:

    AND wpostmeta.meta_value LIKE ‘a%’

    If I change it to:

    AND wpostmeta.meta_value LIKE ‘ab%’

    It will return records. Of course, this is not what I want. I am trying to alpahbetize. Either way it works in MyPHPAdmin. Strange, please help!

    $querystr = “
    SELECT wposts.*
    FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
    WHERE wposts.ID = wpostmeta.post_id
    AND wpostmeta.meta_key = ‘artist’
    AND wpostmeta.meta_value LIKE ‘a%’
    AND wposts.post_status = ‘publish’
    AND wposts.post_type = ‘post’
    AND wposts.post_date < NOW()
    ORDER BY wposts.post_date DESC”;

  • The topic ‘custom query returns nothing, please help!’ is closed to new replies.