是否有内置的wordpress函数让我查找wp_term_taxonomy
如果我通过TT_ID
托伊特?
类似于
get_value ( $wp_table_name, $id_fieldname, $id_value,
$the_field_info_to_retrieve )
示例get_value ( "wp_term_taxonomy", "term_taxonomy_id", "parent");
是否有内置的wordpress函数让我查找wp_term_taxonomy
如果我通过TT_ID
托伊特?
类似于
get_value ( $wp_table_name, $id_fieldname, $id_value,
$the_field_info_to_retrieve )
示例get_value ( "wp_term_taxonomy", "term_taxonomy_id", "parent");
我的经验是,这是分类系统核心的一个问题领域。在某些情况下,核心代码确实会根据tt\\U id或它们的数组获取信息,但在每种情况下,都是在特定函数中使用自定义SQL查询而不是API函数来完成的。
为了解决我自己的问题,我编写了一个简单的helper函数,它可能应该位于core中。它不获取特定字段,而是获取整个term\\u taxonomy行(包括->parent)。最终,这并不比获取单个字段慢,而且由于检查特定ID,这是一个非常快速的查询。
/**
* Fetch the term_taxonomy data for a tt_id from the term_taxonomy table
*
* Should be in core but isn\'t. May need review after updates
* Returns full full row of data but nothing from actual terms table.
*
* @global object $wpdb
* @param integer $tt_id term_taxonomy_id who\'s row you want to fetch.
* @return object Database row object for tt_id (term_id, name, slug, taxonomy, description, parent, count)
*/
function gv_get_term_taxonomy_details($tt_id) {
global $wpdb;
$tt_details_results = $wpdb->get_results("SELECT * FROM $wpdb->term_taxonomy WHERE term_taxonomy_id = ($tt_id)");
$tt_details = $tt_details_results[0];
return $tt_details;
}
试试这个-
$term_id = 4; // term id
$taxonomy = \'category\'; // Taxonomy name that $term_id is part of
$term_data = get_term( $term_id, $taxonomy );
$parent = $term_data->parent; // this return the parent of given term id
参考号:https://codex.wordpress.org/Function_Reference/get_term下面的代码将在用户表(users.php)上创建一列,并显示分类术语的名称。如果您有具有指定自定义角色的用户,则此选项适用于您。数据库将只显示对象中的id,但此代码将从id中提取名称并将其显示在users表中:
<?php
// Display column on user table
add_filter(\'manage_users_columns\', \'column_register_acf_name\');
add_filter(\'manage_users_custom_column\', \'column_display_acf_name\', 10, 3);
function column_register_acf_name($columns)
{
$columns[\'id_col\'] = \'ID Name\';
return $columns;
}
//Adds Content To The Custom Added Column
function get_names($term_id)
{
global $wpdb;
$result = $wpdb->get_var($wpdb->prepare("SELECT name FROM $wpdb->terms WHERE term_id = %d", $term_id));
return $result;
}
function column_display_acf_name($value, $column_name, $user_id)
{
$user_info = get_user_meta($user_id, \'gatekeeper\', true);
$ints = array_map(\'intval\', $user_info);
$names = array_map(\'get_names\', $ints);
if ($column_name == \'id_col\') return implode(\', \', $names);
return implode($value);
}
如果搜索输入与分类名称完全匹配,是否可以将用户重定向到分类页面?例如,我有一个称为“参与者”的分类法。如果有人在搜索字段中输入“Tom Hanks”,而不是进入常规搜索页面,则会将他们重定向到Tom Hanks的分类页面。