WordPress.org

Ready to get started?Download WordPress

Forums

Custom List Table Example
Database query instead of example array (4 posts)

  1. Erixz
    Member
    Posted 8 months ago #

    Hi!

    I have read posts here and Googled around to try to understand how to use custom querys instead of example_data but I do not understand how to do.

    It would be very nice if someone could just show an example with querys or just make a suggestion.

    Thanks in advance!

    http://wordpress.org/plugins/custom-list-table-example/

  2. Matt van Andel
    Member
    Plugin Author

    Posted 6 months ago #

    Hey Erixz,

    You use the $wpdb global object to interact with the WordPress database.

    You can find a very detailed breakdown (with examples!) on the WordPress Codex here:

    http://codex.wordpress.org/Class_Reference/wpdb

    If you are new to plugin development with WordPress, I would encourage you to read the excellent (and free) WordPress Plugin Developer's Handbook, which covers a lot of basics like working with database queries in WordPress.

  3. alfiya
    Member
    Posted 5 months ago #

    Hi Erixz,
    I had the same problem.
    I solved it by inserting a piece of code after "$this->process_bulk_action();"
    The code:
    $query = "SELECT * FROM {$wpdb->posts}";
    $totalitems = $wpdb->query($query);
    $this->items = $wpdb->get_results($query);

    After that you should create a function "display_rows()"
    Please refer to this website http://wp.smashingmagazine.com/2011/11/03/native-admin-tables-wordpress/
    for the details about the "display_rows()" function. Make sure you read the comments because there are some mistakes in the code and users fixed them.

  4. David Macfarlane
    Member
    Posted 5 months ago #

    Line number 383

    Change
    $data = $this->example_data;

    to
    $sql = "SELECT ID,title,rating,director FROM wp_films";
    $data = $wpdb->get_results($sql,ARRAY_A);

    Obviously you'll need to create the database table

    I hope this helps someone

Reply

You must log in to post.

About this Plugin

About this Topic