WordPress“自定义帖子类型”设置了错误的分类术语 ID

发布于 2024-10-31 10:03:56 字数 1510 浏览 4 评论 0原文

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

我觉得图片对于解释事物很有帮助,所以首先,这里有一些问题的说明:

https://i.sstatic.net/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”分类法的子条款似乎也会发生这种情况。

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

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

  • 搜索 Google对于诸如 *“wordpresstax_input bug”*、“wordpress 分类法 ID 错误”、“wordpress 自定义分类法错误” 等,但没有发现匹配的问题

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

    禁用
  • 确保复选框输入具有正确的分类法作为其“名称”和术语 ID 作为其“值”< /p>

  • 破解了 /wp-admin/includes/post.php 核心文件以尝试自行修复。 (不走运。)

  • 今天早上已将问题发布到 [WordPress“操作方法和故障排除”论坛][3](没有回复)

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

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

再次强调,非常感谢任何人的想法或建议 - 谢谢!

First and foremost, I need to stress how greatly I appreciate anyone who takes the time to respond - In advance, thank you, thank you, THANK YOU!

I feel pictures are of great service to explaining things, so to start off, here's something of an illustration of the issue:

https://i.sstatic.net/b9OXR.png

Preface:

  • My site has about 400 Posts under the "dir_listing" Custom Post Type
  • Each "dir_listing" Post can be associated with Terms from the "listing category" Custom Taxonomy and/or "listing_region" Custom Taxonomy
  • I have about 210 "listing_category" Terms, and 155 "listing region" Terms

The Issue in Summary:

When Publishing or Updating a "dir_listing" Post Type, sometimes the Term IDs get recorded into the 'term_relationships' table without issue, and other times are recorded erroneously.

Even so, when I go back to edit one of the "dir_listing" Post Types the checkboxes for the desired Parent/Child Terms are correctly marked.

Actions that could be Related?

  • A number of the "listing_category" terms have been shuffled around. (e.g. A Parent term has become a Child term, or vice-versa, or a Child term has been moved to another Parent.)

  • Both Parent & Child Terms have been renamed without making any changes to the "dir_listing" Post types. (I don't think this matters, since Posts are supposed to be related to Terms by ID #)

  • A number of Parent Terms and Child Terms may have been deleted by another Admin-level user. This also seems to happen with Child-Terms of the "listing_regions" taxonomy.

How I've Investigated / Tried to Fix It:

  • Extensively searched WordPress trac (No similar issues reported)

  • Searched Google for things like *"wordpress tax_input bug"*, "wordpress taxonomy id bug", "wordpress custom taxonomy bug", etc. and found no matching issues

  • Disabled all plugins, custom rewrites, and other taxonomies

  • Ensured the checkbox inputs had the correct Taxonomy as their 'name' and Term ID as their 'value'

  • Hacked the /wp-admin/includes/post.php core file to try to fix it myself. (No luck.)

  • Posted issue to [WordPress "How-To and Troubleshooting" forum][3] this morning (No replies)

  • Posted issue to Reddit /r/web_design this afternoon (Also no replies)

I've spent the better part of 8 hours trying to determine the cause of this, or if I'm missing a step by using a custom MySQL query to directly get a list of Posts related to a particular Term ID.

Again, any thoughts or suggestions anyone might have are VERY MUCH appreciated - Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苏别ゝ 2024-11-07 10:03:56

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

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

另请参阅 此 trac 票证涉及帖子关系表的需求和一些用例。

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

This info might help you with how the term_id and and term_taxonomy_id work. It seems like there are a lot of conditions that effect the final outcome of how the ids are set.

See the full reference here: http://phpxref.com/xref/wordpress/wp-includes/taxonomy.php.html#wp_insert_term

Also have a look at this trac ticket regarding the need for a posts relationship table and some of the use cases.

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文