WordPress $wpdb Cheat Sheet

A Software › WordPress cheat sheet in English by husker

$wpdb functions syntax

10,810 views 2,860 downloads 28 Jan 2020 History
3.7 avg · 0 ratings

$wpdb-­>ge­t_var

$wpdb-­>ge­t_var( '­que­ry' );
$wpdb-­>ge­t_var( '­que­ry', column­_of­fset, row_offset );
Ex: $user_­count = $wpdb-­>ge­t_var( "­SELECT COUNT(*) FROM $wpdb-­>us­ers­" );

$wpdb-­>ge­t_row

$wpdb-­>ge­t_r­ow(­'­que­ry', output­_type, row_of­fset);
OBJECT - result will be output as an object.
ARRAY_A - result will be output as an associ­ative array
ARRAY_N - result will be output as a numeri­cally indexed array.

$wpdb-­>ge­t_col

$wpdb-­>ge­t_col( '­que­ry', column­_offset );

$wpdb-­>ge­t_r­esults

$wpdb-­>ge­t_r­esults( '­que­ry', output­_type );
OBJECT - result will be output as a numeri­cally indexed array of row objects.
OBJECT_K - result will be output as an associ­ative array of row objects, using first column­'s values as keys (dupli­cates will be discarded).
ARRAY_A - result will be output as a numeri­cally indexed array of associ­ative arrays, using column names as keys.
ARRAY_N - result will be output as a numeri­cally indexed array of numeri­cally indexed arrays.

$wpdb-­>insert

$wpdb-­>in­sert( $table, $data, $format );

$wpdb-­>re­place

$wpdb-­>re­place( $table, $data, $format );

$wpdb-­>update

$wpdb-­>up­date( $table, $data, $where, $format = null, $where­_format = null );

$wpdb-­>delete

$wpdb-­>de­lete( $table, $where, $where­_format = null );

$wpdb-­>query

$wpdb-­>qu­ery­('qu­ery­');

$wpdb-­>pr­epare

$sql = $wpdb-­>pr­epare( '­que­ry' , value_­par­ame­ter[, value_­par­ameter ... ] );

Badges

Nice Cheat Sheet

Comments

No comments yet.

Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.