以编程方式添加TERMS/TERM_TASTIONIES时出现异常行为

时间:2012-04-20 作者:Average Joe

这在我看来确实像个虫子。我为您编写了以下代码,以便在新安装上对其进行测试。基本上,代码将在“未分类”下添加两个子类别,以实现以下效果

uncategorized
   sub-uncategorized
       sub-sub-uncategorized
将它们添加到wp\\U terms和wp\\U term\\u分类中没有问题。已正确添加两个父ID。

问题出在wp管理ui中。您只能看到未分类和子未分类。最后一个(sub-sub)在运行中丢失!

但是,如果您在同一个“添加类别”页面上转到父下拉选择,您将看到子uncat和“子sub cat”都出现在那里,并正确缩进-完全出现在以下正确的层次结构中

uncategorized
   sub-uncategorized
       sub-sub-uncategorized
要将缺少的sub-sub-cat引入主视图,必须执行以下步骤之一;

您可以通过停止和启动来回收wp。

或者简单地添加一只假猫,然后单击“类别”链接列出所有猫。然后wp记住正确显示SUB。

有人知道为什么会这样吗?

我很感激任何有计划的补救措施,这样我就不必经历愚蠢的步骤,而不仅仅是为了让猫进入视野。

代码如下所示。只需调整wp负载即可。php路径,然后才能在新安装上测试它,然后自己检查上面所述的内容。

<?php

error_reporting (E_ALL);

//load the wp shebang into this page
include (" put the full path here to the wp-load.php");


define(\'WP_USE_THEMES\', false);


//add a sub category under the "uncategorized" that fresh install comes with
$Term = "Sub-UnCategorized";
$args = array(\'parent\' => 1 );
wp_insert_term($Term, "category", $args);


//add another sub under the recentyl created above. 
$Term = "Sub-Sub-UnCategorized";
$args = array(\'parent\' => 3 );
wp_insert_term($Term, "category", $args);

echo "<pre>

After running this code, you will notice that the Sub-Sub-UnCategorized is missing from the view. 

But what\'s funny is the dropdown. 
Check the dropdown for the *parent* selection, you will see that the missing
Sub-Sub-UnCategorized is there. 

In order to get the missing sub-sub into the view, you will have to do two things. 

1 - Add a dummy cat.
2 - Click on the categories link on the admin navigation.

With that, wp will sort this problem out and you will see everything you should have.

I cannot figure out what\'s causing this behavior and how to remedy this short adding the dummy cat and removing it later. 

</pre>";

?>

1 个回复
SO网友:ifdion

也许这会有帮助

delete_option(\'taxonomy-slug_children\');
只需用“cat”或您正在使用的其他分类法替换“taxonomy slug”。这一行应该在创建术语后立即在同一个动作挂钩函数中使用。

结束

相关推荐

在wp-admin中更改默认页面菜单视图

我似乎不知道如何更改管理菜单中“页面”的默认视图。初始视图是“页面”视图(/wp-admin/edit.php?post_type=page)它怎么能把这个改变成其他东西呢像“添加新页面”一样?(/wp-admin/post-new.php?post_type=page)我尝试了几种不同的选项,包括用自定义菜单重建菜单,但WordPress似乎会自动重定向“页面”视图(/wp-admin/edit.php?post_type=page).