3 | | The first set of test deal with an hierarchical taxonomy, and they all pass, including the new one that verifies that `('get' => 'all)' works as expected. |
4 | | |
5 | | The problem is that I then go on to test a flat taxonomy, and the act of assigning terms to a post actually creates new terms, and I can't figure out why. The code in question is |
6 | | |
7 | | |
8 | | {{{ |
9 | | $flat_tax = 'countries'; |
10 | | register_taxonomy( $flat_tax, 'post', array( 'hierarchical' => false ) ); |
11 | | $australia = $this->factory->term->create( array( 'name' => 'Australia', 'taxonomy' => $flat_tax ) ); |
12 | | $china = $this->factory->term->create( array( 'name' => 'China', 'taxonomy' => $flat_tax ) ); |
13 | | $tanzania = $this->factory->term->create( array( 'name' => 'Tanzania', 'taxonomy' => $flat_tax ) ); |
14 | | |
15 | | $post4_id = $this->factory->post->create(); |
16 | | $post5_id = $this->factory->post->create(); |
17 | | |
18 | | |
19 | | // Check 1 |
20 | | $terms = get_terms( $flat_tax, array( 'childless' => true, 'hide_empty' => false) ); |
21 | | error_log( print_r( $terms )); |
22 | | wp_set_post_terms( $post4_id, $montreal, $flat_tax ); |
23 | | wp_set_post_terms( $post5_id, $ottawa, $flat_tax ); |
24 | | // Check 2 |
25 | | $terms = get_terms( $flat_tax, array( 'childless' => true, 'hide_empty' => false) ); |
26 | | error_log( print_r( $terms )); |
27 | | }}} |
28 | | |
29 | | |
30 | | The results of Check 1 and 2 should be the same, but they are not. Check 1 shows the three terms as expected, but Check 2 shows the three terms plus two more that are just numbers, not text. For example |
31 | | |
32 | | Check 1 |
33 | | |
34 | | {{{ |
35 | | Array |
36 | | ( |
37 | | [0] => stdClass Object |
38 | | ( |
39 | | [term_id] => 10 |
40 | | [name] => Australia |
41 | | [slug] => australia |
42 | | [term_group] => 0 |
43 | | [term_taxonomy_id] => 10 |
44 | | [taxonomy] => countries |
45 | | [description] => Term description 9 |
46 | | [parent] => 0 |
47 | | [count] => 0 |
48 | | ) |
49 | | |
50 | | [1] => stdClass Object |
51 | | ( |
52 | | [term_id] => 11 |
53 | | [name] => China |
54 | | [slug] => china |
55 | | [term_group] => 0 |
56 | | [term_taxonomy_id] => 11 |
57 | | [taxonomy] => countries |
58 | | [description] => Term description 10 |
59 | | [parent] => 0 |
60 | | [count] => 0 |
61 | | ) |
62 | | |
63 | | [2] => stdClass Object |
64 | | ( |
65 | | [term_id] => 12 |
66 | | [name] => Tanzania |
67 | | [slug] => tanzania |
68 | | [term_group] => 0 |
69 | | [term_taxonomy_id] => 12 |
70 | | [taxonomy] => countries |
71 | | [description] => Term description 11 |
72 | | [parent] => 0 |
73 | | [count] => 0 |
74 | | ) |
75 | | |
76 | | ) |
77 | | }}} |
78 | | |
79 | | |
80 | | Check 2 |
81 | | |
82 | | |
83 | | {{{ |
84 | | Array |
85 | | ( |
86 | | [0] => stdClass Object |
87 | | ( |
88 | | [term_id] => 14 |
89 | | [name] => 7 |
90 | | [slug] => 7 |
91 | | [term_group] => 0 |
92 | | [term_taxonomy_id] => 14 |
93 | | [taxonomy] => countries |
94 | | [description] => |
95 | | [parent] => 0 |
96 | | [count] => 1 |
97 | | ) |
98 | | |
99 | | [1] => stdClass Object |
100 | | ( |
101 | | [term_id] => 13 |
102 | | [name] => 8 |
103 | | [slug] => 8 |
104 | | [term_group] => 0 |
105 | | [term_taxonomy_id] => 13 |
106 | | [taxonomy] => countries |
107 | | [description] => |
108 | | [parent] => 0 |
109 | | [count] => 1 |
110 | | ) |
111 | | |
112 | | [2] => stdClass Object |
113 | | ( |
114 | | [term_id] => 10 |
115 | | [name] => Australia |
116 | | [slug] => australia |
117 | | [term_group] => 0 |
118 | | [term_taxonomy_id] => 10 |
119 | | [taxonomy] => countries |
120 | | [description] => Term description 9 |
121 | | [parent] => 0 |
122 | | [count] => 0 |
123 | | ) |
124 | | |
125 | | [3] => stdClass Object |
126 | | ( |
127 | | [term_id] => 11 |
128 | | [name] => China |
129 | | [slug] => china |
130 | | [term_group] => 0 |
131 | | [term_taxonomy_id] => 11 |
132 | | [taxonomy] => countries |
133 | | [description] => Term description 10 |
134 | | [parent] => 0 |
135 | | [count] => 0 |
136 | | ) |
137 | | |
138 | | [4] => stdClass Object |
139 | | ( |
140 | | [term_id] => 12 |
141 | | [name] => Tanzania |
142 | | [slug] => tanzania |
143 | | [term_group] => 0 |
144 | | [term_taxonomy_id] => 12 |
145 | | [taxonomy] => countries |
146 | | [description] => Term description 11 |
147 | | [parent] => 0 |
148 | | [count] => 0 |
149 | | ) |
150 | | |
151 | | ) |
152 | | |
153 | | }}} |
154 | | |
155 | | This is implying that the `wp_set_post_terms` is adding the bad terms, but I don't understand why because the arguments seems fine: the first is `6, 11, countries` and the second is `7, 12, countries`. |
156 | | |
157 | | This false term insertion makes all assertions fail. |
158 | | |
159 | | Does anything jump out at you? I'm going around in circles. |
| 3 | False alarm. Still working on it. |