-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
63 lines (50 loc) · 1.2 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
//Fetch data from database
function wp_form_data_fetch( $args = [] ) {
global $wpdb;
$defaults = [
'number' => 10,
'offset' => 0,
'orderby' => 'id',
'order' => 'DESC',
];
$args = wp_parse_args( $args, $defaults );
$items = $wpdb->get_results(
$wpdb->prepare(
"SELECT * FROM {$wpdb->prefix}wp_form
ORDER BY {$args['orderby']} {$args['order']}
LIMIT %d, %d",
$args['offset'],
$args['number']
)
);
return $items;
}
//Fetch data from database
function wp_form_data_count() {
global $wpdb;
$count = $wpdb->get_var(
"SELECT COUNT(*) FROM {$wpdb->prefix}wp_form"
);
return $count;
}
//fetch single data from database by id
function wp_form_get_data_by_id( $id ) {
global $wpdb;
$item = $wpdb->get_row(
$wpdb->prepare(
"SELECT * FROM {$wpdb->prefix}wp_form WHERE id = %d",
$id
)
);
return $item;
}
// delete single data from database
function wp_form_delete_data( $id ) {
global $wpdb;
$wpdb->delete(
$wpdb->prefix . 'wp_form',
['id' => $id],
['%d']
);
}