Support » Plugin: Custom List Table Example » [Plugin: Custom List Table Example] query the database

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hi, i have the same problem, i don’t understand how to do a query to my db and show result in the table.

    Have you find a solution?


    To use a proper database connection, do the following:

    At about line 317, inside function prepare_items(), insert:

    global $wpdb;

    Then, replace line 361 with something like this:

    $querydata = $wpdb->get_results(
    	SELECT * FROM wp_my_movie_table WHERE 1

    The example plugin used a nested array to hold the data, but the database query will return an array of objects. It is probably better to use the objects directly, but now we’ll simply re-cast so that the plugin still works without changing code elsewhere..

    Insert after the database query:

    foreach ($querydata as $querydatum ) {
       array_push($data, (array)$querydatum);}

    Don’t forget to create the wp_my_movie_table database table.

    It should work now, and you can go back and clean up the unnecessary code that references $example_data.

    This example is excellent, but would be vastly more useful with auto table creation and removal, complete CRUD functionality, etc.

    @superpotion thanks for your help can you please help me how i can edit or delete via this example?

    Plugin Author Matt van Andel


    The plugin foregoes any kind of database direction since a basic understanding of WordPress’s $wpdb object is both a bit of a given and a different topic entirely.

    You can read up on WordPress’s database object here:

    While it’s no Zend or CakePHP, it’s fairly easy to get the hang of.

    Thanks a lot for this…..
    I’ve googled it since 1 days…. and didnt find anything good…
    But this works for me …..

    Thanks Supermotion Member. Got it to work as well. Now to find out how I can actually edit and delete things 🙂

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘[Plugin: Custom List Table Example] query the database’ is closed to new replies.