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/
原文链接:https://xiaohost.com/5267.html,转载请注明出处。