WordPress - post_parent的sum元值

时间:2013-12-27 09:26:02

标签: wordpress wpdb

我正在尝试运行WPDB查询以计算post meta的值:

Sum meta Value by post_id which have post_parent = xx

我有一个WPDB代码,但我不知道如何通过post_parent:

$wpdb->get_results("SELECT SUM($wpdb->postmeta.meta_value) 
      FROM $wpdb->postmeta WHERE `post_id` = get_the_ID()");

1 个答案:

答案 0 :(得分:-1)

$wpdb->get_results("SELECT SUM( wp_postmeta.meta_value )
FROM wp_postmeta
WHERE wp_postmeta.post_id =".get_the_ID());