wordpress 计算自定义字段值的和示例代码

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
// set the meta_key to the appropriate custom field meta key
$meta_key = 'miles';
$allmiles = $wpdb->get_var(
    $wpdb->prepare(
        "
            SELECT sum(meta_value)
            FROM $wpdb->postmeta
            WHERE meta_key = %s
        ",
        $meta_key
    )
);
echo "<p>Total miles is {$allmiles}</p>";
?>

有关$wpdb的使用更多信息详见https://developer.wordpress.org/reference/classes/wpdb/

报歉!评论已关闭.