Skip to main content
Wrapped example in a function, callable via wp_ajax
Source Link

I would recommend using WordPress function calls to set up your terms, instead of SQL. This is assuming you've already registered a custom taxonomy called job_listing_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');

Now you can call this function by going to the URL http://your-blog.tld/wp-admin/admin-ajax.php?action=convert_meta_to_term.

I would recommend using WordPress function calls to set up your terms, instead of SQL. This is assuming you've already registered a custom taxonomy called job_listing_region.

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);
}

I would recommend using WordPress function calls to set up your terms, instead of SQL. This is assuming you've already registered a custom taxonomy called job_listing_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');

Now you can call this function by going to the URL http://your-blog.tld/wp-admin/admin-ajax.php?action=convert_meta_to_term.

Source Link

I would recommend using WordPress function calls to set up your terms, instead of SQL. This is assuming you've already registered a custom taxonomy called job_listing_region.

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);
}