WordPress.org

Ready to get started?Download WordPress

Forums

custom query returns nothing, please help! (1 post)

  1. webhead2
    Member
    Posted 5 years ago #

    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";

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags