# WordPress - Developer Resources ###### tags: `PHP` `WordPress` > **Date**:2023/03/15 > **Taker**:Sin This document provides a collection of useful WordPress functions for developers. ## Functions ### Retrieve a Single Row from the Database The following function retrieves a single row from the specified database table. Replace `{{table_name}}` with the name of your table. ```php global $wpdb; $data = $wpdb->get_row('SELECT * FROM ' . $wpdb->prefix . '{{table_name}}'); ``` [Reference](https://developer.wordpress.org/reference/classes/wpdb/get_row/) ### Retrieve an Entire SQL Result Set from the Database This function retrieves an entire SQL result set from the specified database table. Replace `{{table_name}}` with the name of your table. ```php global $wpdb; $data = $wpdb->get_results('SELECT * FROM ' . $wpdb->prefix . '{{table_name}}'); ``` [Reference](https://developer.wordpress.org/reference/classes/wpdb/get_results/) ### Get the Current User's ID This function retrieves the ID of the current user. If no user is logged in, it returns 0. ```php $user_id = get_current_user_id(); ``` [Reference](https://developer.wordpress.org/reference/functions/get_current_user_id/) ### Retrieve the Current User Object This function retrieves the current user object. ```php $user = wp_get_current_user(); ``` ### Get Order `donate_title` and `title_type` This function retrieves the `donate_title` and `title_type` from the `postmeta` table for all completed orders. ```php global $wpdb; $data = $wpdb->get_results('SELECT order_id FROM ' . $wpdb->prefix . "wc_order_stats WHERE status = 'wc-completed' ORDER BY order_id DESC", 'ARRAY_A'); $orderIds = array_column($data, 'order_id'); $ret = $wpdb->get_results('SELECT meta_key, meta_value FROM ' . $wpdb->prefix . "postmeta WHERE post_id IN (" . implode(",", $orderIds) . ") AND (meta_key = 'donate_title' OR meta_key = 'title_type' OR meta_key = '_date_paid') ORDER BY post_id DESC", 'ARRAY_A'); var_dump($ret); ``` ## References 1. [WordPress Developer Resources](https://developer.wordpress.org/)