WordPress的“自定义帖子类型”设置为错误的分类条款ID

时间:2011-04-11 22:39:27

标签: mysql database wordpress taxonomy

首先,我要强调我非常感谢任何花时间回复的人 - 提前,谢谢,谢谢,谢谢!

我觉得图片对解释事物很有帮助,所以首先,这里有一个问题的例子:

http://i.stack.imgur.com/b9OXR.png

前言

  • 我的网站在“dir_listing”自定义帖子类型
  • 下有大约400个帖子
  • 每个“dir_listing”帖子都可以与“列表类别”自定义分类和/或“listing_region”自定义分类
  • 中的条款相关联
  • 我有大约210个“listing_category”条款和155个“列表区域”条款

摘要中的问题:

发布或更新“dir_listing”帖子类型时,有时会将术语ID记录到“term_relationships”表中而不会出现问题,并且有时会错误地记录。

即便如此,当我回去编辑其中一个“dir_listing”帖子类型时,正确标记了所需父母/子女条款的复选框。

可能相关的操作?

  • 许多“listing_category”术语已被改组。 (例如,父母用语已成为子用语,反之亦然,或者子用语已移至另一个父级。)

  • 父母与父母已重命名子条款,而不对“dir_listing”帖子类型进行任何更改。 (我认为这不重要,因为帖子应该通过ID#与条款相关)

  • 许多家长条款和子条款可能已被其他管理员级用户删除。这似乎也发生在“listing_regions”分类标准的Child-Terms中。

我如何调查/尝试修复它:

  • 广泛搜索的WordPress trac(未报告类似问题)

  • 在谷歌搜索*“wordpress tax_input bug”*,“wordpress taxonomy id bug”“wordpress custom taxonomy bug”等等。未发现匹配问题

  • 禁用所有插件,自定义重写和其他分类

  • 确保复选框输入具有正确的分类标准作为其“名称”,术语ID作为其“值”

  • 黑客攻击/wp-admin/includes/post.php核心文件,尝试自行修复。 (没有运气。)

  • 今天早上将问题发布到[WordPress“操作方法和疑难解答”论坛] [3](无回复)

  • 今天下午向Reddit / r / web_design发布了问题(也没有回复)

我花了8个小时的大部分时间试图确定原因,如果我错过了一个步骤,通过使用自定义MySQL查询来直接获取帖子列表相关到特定的术语ID。

同样,任何人可能有的任何想法或建议都非常感激 - 谢谢!

1 个答案:

答案 0 :(得分:0)

此信息可能会帮助您了解term_id和term_taxonomy_id的工作原理。似乎有很多条件影响了如何设置ID的最终结果。

请参阅此处的完整参考资料:http://phpxref.com/xref/wordpress/wp-includes/taxonomy.php.html#wp_insert_term

另请参阅this trac ticket关于帖子关系表和一些用例的需求。

get_term($term, $taxonomy, $output = OBJECT, $filter = 'raw')   X-Ref
Get all Term data from database by Term ID.

The usage of the get_term function is to apply filters to a term object. It
is possible to get a term object from the database before applying the
filters.

$term ID must be part of $taxonomy, to get from the database. Failure, might
be able to be captured by the hooks. Failure would be the same value as $wpdb
returns for the get_row method.

There are two hooks, one is specifically for each term, named 'get_term', and
the second is for the taxonomy name, 'term_$taxonomy'. Both hooks gets the
term object, and the taxonomy name as parameters. Both hooks are expected to
return a Term object.

'get_term' hook - Takes two parameters the term Object and the taxonomy name.
Must return term object. Used in get_term() as a catch-all filter for every
$term.

'get_$taxonomy' hook - Takes two parameters the term Object and the taxonomy
name. Must return term object. $taxonomy will be the taxonomy name, so for
example, if 'category', it would be 'get_category' as the filter name. Useful
for custom taxonomies or plugging into default taxonomies.

param: int|object $term If integer, will get from database. If object will apply filters and return $term.
param: string $taxonomy Taxonomy name that $term is part of.
param: string $output Constant OBJECT, ARRAY_A, or ARRAY_N
param: string $filter Optional, default is raw or no WordPress defined filter will applied.
return: mixed|null|WP_Error Term Row from database. Will return null if $term is empty. If taxonomy does not

get_term_by($field, $value, $taxonomy, $output = OBJECT, $filter = 'raw')   X-Ref
Get all Term data from database by Term field and data.

Warning: $value is not escaped for 'name' $field. You must do it yourself, if
required.

The default $field is 'id', therefore it is possible to also use null for
field, but not recommended that you do so.

If $value does not exist, the return value will be false. If $taxonomy exists
and $field and $value combinations exist, the Term will be returned.

param: string $field Either 'slug', 'name', or 'id'
param: string|int $value Search for this term value
param: string $taxonomy Taxonomy Name
param: string $output Constant OBJECT, ARRAY_A, or ARRAY_N
param: string $filter Optional, default is raw or no WordPress defined filter will applied.
return: mixed Term Row from database. Will return false if $taxonomy does not exist or $term was not found.

get_term_children( $term_id, $taxonomy )   X-Ref
Merge all term children into a single array of their IDs.

This recursive function will merge all of the children of $term into the same
array of term IDs. Only useful for taxonomies which are hierarchical.

Will return an empty array if $term does not exist in $taxonomy.

param: string $term ID of Term to get children
param: string $taxonomy Taxonomy Name
return: array|WP_Error List of Term Objects. WP_Error returned if $taxonomy does not exist