• rodeored

    (@rodeored)


    I have wordpress 3.8.1
    For the most part, the site runs fine, but when I try to make my own queries on a table I created, the wpdb object is not working as expected.
    In php admin, I can see table playlists with 4 rows, but the WordPress database functions don’t find any rows

    $sql=”SELECT * FROM wp_playlists”;
    $playlists = $wpdb->get_results($sql);

    This returns an empty array
    $playlists:0 rows
    Array
    (
    )

    Another example:
    $playlists = $wpdb->query( “SELECT * FROM wp_playlists”);
    $playlists:[4];

    Instead of returning all the fields of all the rows, it simply returns the number of rows.

    What could be causing this problem?

Viewing 3 replies - 1 through 3 (of 3 total)
  • vtxyzzy

    (@vtxyzzy)

    Is the name of the table actually ‘wp_playlists’? Is that what shows in phpMyAdmin?

    Thread Starter rodeored

    (@rodeored)

    Yes, that’s what shows in phpMyAdmin

    vtxyzzy

    (@vtxyzzy)

    You may need to declare $wpdb as global:

    global $wpdb;
    $sql="SELECT * FROM wp_playlists";
    $playlists = $wpdb->get_results($sql);
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘wordpress $wpdb queries’ is closed to new replies.