今天遇到一个很奇怪的问题,同样的get_terms代码在两个地方调用,一个是正常的,一个却提示invalid_taxonomy无效分类法,我怀疑是不是这个分类法的声明的先后问题。

&amp;lt;p&amp;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">=&gt;</span> <span class="str">"course"</span><span class="pun">,</span><span class="str">"hide_empty"</span> <span class="pun">=&gt;</span> <span class="kwd">false</span><span class="pun">,</span><span class="str">"parent"</span> <span class="pun">=&gt;</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>。&amp;lt;/p&amp;gt; 

这个代码就提示无效。

&amp;lt;p&amp;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">=&gt;</span> <span class="str">"course"</span><span class="pun">,</span><span class="str">"hide_empty"</span> <span class="pun">=&gt;</span> <span class="kwd">false</span><span class="pun">,</span><span class="str">"parent"</span> <span class="pun">=&gt;</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">-&gt;</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>&amp;lt;/p&amp;gt; 

这个代码就正常。

最终模板兔找到的问题所在,就是在处理filter的时候,优先级可以适当设置大点。


 

相关新闻

在线客服
在线客服
SHARE
TOP