今天遇到一个很奇怪的问题,同样的get_terms代码在两个地方调用,一个是正常的,一个却提示invalid_taxonomy无效分类法,我怀疑是不是这个分类法的声明的先后问题。
&lt;p&gt;</pre> <pre class="prettyprint"><span class="pln">$coursess </span><span class="pun">=</span> <span class="wp_keywordlink_affiliate"><a title="View all posts in get_terms" href="https://www.mobantu.com/tag/get_terms" target="_blank" rel="noopener"><span class="pln">get_terms</span></a></span><span class="pun">(</span><span class="pln"> array</span><span class="pun">(</span><span class="str">"taxonomy"</span> <span class="pun">=></span> <span class="str">"course"</span><span class="pun">,</span><span class="str">"hide_empty"</span> <span class="pun">=></span> <span class="kwd">false</span><span class="pun">,</span><span class="str">"parent"</span> <span class="pun">=></span> <span class="lit">0</span><span class="pun">)</span> <span class="pun">);</span><span class="pln"> var_dump</span><span class="pun">(</span><span class="pln">$coursess</span><span class="pun">);</span></pre> <pre>。&lt;/p&gt;
这个代码就提示无效。
&lt;p&gt;</pre> <pre class="prettyprint"><span class="pln">$the_query </span><span class="pun">=</span> <span class="kwd">new</span><span class="pln"> WP_Term_Query</span><span class="pun">(</span><span class="pln">array</span><span class="pun">(</span><span class="str">"taxonomy"</span> <span class="pun">=></span> <span class="str">"course"</span><span class="pun">,</span><span class="str">"hide_empty"</span> <span class="pun">=></span> <span class="kwd">false</span><span class="pun">,</span><span class="str">"parent"</span> <span class="pun">=></span> <span class="lit">0</span><span class="pun">));</span><span class="pln"> var_dump</span><span class="pun">(</span><span class="pln">$the_query</span><span class="pun">-></span><span class="wp_keywordlink_affiliate"><a title="View all posts in get_terms" href="https://www.mobantu.com/tag/get_terms" target="_blank" rel="noopener"><span class="pln">get_terms</span></a></span><span class="pun">());</span></pre> <pre>&lt;/p&gt;
这个代码就正常。
最终模板兔找到的问题所在,就是在处理filter的时候,优先级可以适当设置大点。