尝试使用get_term_by()
, 其中第一个参数是一个字段,在您的案例中是名称。其次是你的价值。我用过esc_attr()
使其安全。第三个是分类学,我在这里举了一个例子category
.
if ($_SERVER["REQUEST_METHOD"] == "GET" && $_GET[\'fname2\'] && $_GET[\'fname\']) {
$nameb = get_term_by(\'name\', esc_attr($_GET[\'fname2\']), \'category\');
$namea = get_term_by(\'name\', esc_attr($_GET[\'fname\']), \'category\');
}
//check if there is an objects
if( $nameb instanceof WP_Term && $nameb instanceof WP_Term ){
echo $nameb->term_id;
echo $namea->name;
}
参考一些示例-
here返回的对象:
(object) array(
\'term_id\' => 49,
\'name\' => \'Term Name\',
\'slug\' => \'term-name\',
\'term_group\' => 0,
\'term_taxonomy_id\' => 49,
\'taxonomy\' => \'category\',
\'description\' => \'\',
\'parent\' => 0,
\'count\' => 286,
\'filter\' => \'raw\',
)