BD Wordpress - table: wp_term_relationships
object_id | term_taxonomy_id| term_order
1 | 23 | 0
2 | 22 | 0
3 | 23 | 0
4 | 22 | 0
5 | 23 | 0
6 | 21 | 0
I need to count how many 'products' belong in every 'category' and insert at column 'term_order'
for example:
object_id | term_taxonomy_id| term_order
1 | 23 | 3
2 | 22 | 2
3 | 23 | 3
4 | 22 | 2
5 | 23 | 3
6 | 21 | 1
I did something like this, but it is not updating the field 'term_order':
UPDATE `letras`.`wp_term_relationships`
SET `term_order` = '2'
WHERE `wp_term_relationships`.`object_id` = '5' ;
SELECT object_id as id_objeto,
COUNT( `object_id` ) quantidade
FROM wp_term_relationships
WHERE `object_id` = `object_id`
GROUP BY `term_taxonomy_id`