Function to retrieve all post data from custom table

Support MB Custom Table Function to retrieve all post data from custom tableResolved

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #12550
    JeffersonJefferson
    Participant

    Exists some function like get_post() that can I use to retrieve all post (relative) data from custom table?

    If not, each field requires a database call?

    #12557
    Anh TranAnh Tran
    Keymaster

    Hi Jefferson,

    To get all fields from custom table, you can do a simple query:

    global $wpdb;
    $fields = $wpdb->get_row( "SELECT * FROM your_table WHERE ID={$post_id}" );
    echo $fields->your_field;

    If you use the helper function to get a field value, it will create a very similar query and cache the result. So the next call to get another field's value, it won't create any extra DB query.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.