我建议使用WordPress函数调用来设置术语,而不是SQL。这是假设你已经registered 一种称为job\\u listing\\u region的自定义分类法。
// Add this to your theme\'s functions.php
function convert_meta_to_term() {
global $wpdb;
$meta_query = $wpdb->get_results("
SELECT *
FROM $wpdb->postmeta
WHERE meta_key = \'job_listing_region\'
");
foreach ($meta_query as $meta) {
// Append new terms for each post
wp_set_object_terms($meta->post_id, $meta->meta_value, \'job_listing_region\', true);
}
}
add_action(\'wp_ajax_convert_meta_to_term\', \'convert_meta_to_term\');
现在您可以通过转到URL调用此函数
http://your-blog.tld/wp-admin/admin-ajax.php?action=convert_meta_to_term
.