develog

[wordpress] $wpdb 본문

카테고리 없음

[wordpress] $wpdb

냐옴 2024. 5. 28. 15:46

 

// %s (string)
// %d (integer)
// %f (float)
// like % -> like %%
$wpdb->prepare

// select
$wpdb->get_results  // multi row, multi column
$wpdb->get_row      // one row, multi column
$wpdb->get_col      // multi row, one column
$wpdb->get_var      // one value (one row, one column)


// insert, update, delete
$wpdb->query

$query = $wpdb->prepare(
    "INSERT INTO $wpdb->postmeta ( post_id, meta_key, meta_value ) VALUES ( %d, %s, %s )",
        10,
        $metakey,
        $metavalue
);

$wpdb->query($query);

 

Comments