first of all, sorry, i'm not good in mySQL right now.
I've got 2 tables:
post_meta
id | post_id | page_num
4 | 161 | 14
3 | 160 | 9
2 | 159 | 3
1 | 158 | 16
And:
wp_posts
id | date | parent_id
161 | 2013-08-28 13:53:48 | 160
160 | 2013-07-28 13:53:48 | 0
159 | 2013-04-28 13:53:48 | 158
158 | 2013-02-28 13:53:48 | 0
I want to know the sum of all page_nums for the posts where the date is 2013. The problem is that 1 single post got severals other post which got the parent_id from the parent post.
In this example the id 160 is the parent post in wp_posts and got a child post with the id 161. But it's the same single post.
The page_num from post_meta got the post_id from each post even it's a child. In this case it would be id 4 and 2 from post_meta since that are the latest saves for the parent posts 160 and 159.
So i only need to sum up only the page_nums for the latest (newest) child post.
My (very bad) try so far:
COUNT pagenum FROM wp_postmeta a WHERE wp_postmeta b post_id.b = parent_id.a AND DATE LIKE='2014' GROUP BY parent_id.b
I hope you understand the problem.
Thanks for your help in advance and
best regards