Exemplo n.º 1
0
 protected function _insertTestData()
 {
     register_taxonomy('public_taxonomy_a', array('post', 'page'), array('public' => true));
     register_taxonomy('private_taxonomy_a', array('post'), array('public' => false));
     $post_id_a = wp_insert_post(array('post_status' => 'publish', 'post_type' => 'post', 'post_author' => 1, 'post_parent' => 0, 'menu_order' => 0, 'post_content_filtered' => '', 'post_excerpt' => 'This is the excerpt.', 'post_content' => 'This is the content.', 'post_title' => 'Hello World A!', 'post_date' => '2013-04-30 20:33:36', 'post_date_gmt' => '2013-04-30 20:33:36', 'comment_status' => 'open'));
     $post_id_b = wp_insert_post(array('post_status' => 'publish', 'post_type' => 'post', 'post_author' => 1, 'post_parent' => 0, 'menu_order' => 0, 'post_content_filtered' => '', 'post_excerpt' => 'This is the excerpt.', 'post_content' => 'This is the content.', 'post_title' => 'Hello World B!', 'post_date' => '2013-04-30 20:33:36', 'post_date_gmt' => '2013-04-30 20:33:36', 'comment_status' => 'open'));
     $term_a = wp_create_term('Term In Both', 'public_taxonomy_a');
     $term_b = wp_create_term('Term In A', 'public_taxonomy_a');
     $term_c = wp_create_term('Term In B', 'public_taxonomy_a');
     $term_d = wp_create_term('Term In None', 'public_taxonomy_a');
     $term_e = wp_create_term('Term In Private', 'private_taxonomy_a');
     wp_set_object_terms($post_id_a, array(intval($term_a['term_id']), intval($term_b['term_id'])), 'public_taxonomy_a');
     wp_set_object_terms($post_id_b, array(intval($term_c['term_id'])), 'public_taxonomy_a');
     wp_set_object_terms($post_id_a, array(intval($term_e['term_id'])), 'private_taxonomy_a');
     return compact('post_id_a', 'post_id_b', 'term_a', 'term_b', 'term_c', 'term_d', 'term_e');
 }
Exemplo n.º 2
0
/**
 * Add a new tag to the database if it does not already exist.
 *
 * @since 2.3.0
 *
 * @param int|string $tag_name
 * @return array|WP_Error
 */
function wp_create_tag($tag_name)
{
    return wp_create_term($tag_name, 'post_tag');
}
Exemplo n.º 3
0
/**
 * Save our data once the user publishes or saves their post.
 */
function wanderlist_save_metabox_data($post_id, $post, $update)
{
    // Make sure our nonce has been correctly set.
    if (!isset($_POST['meta-box-nonce']) || !wp_verify_nonce($_POST['meta-box-nonce'], basename(__FILE__))) {
        return $post_id;
    }
    // Make sure the user has permissions to edit this post.
    if (!current_user_can('edit_post', $post_id)) {
        return $post_id;
    }
    // If we're autosaving, don't worry about it right now.
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return $post_id;
    }
    // Check to ensure that our post type is the same as our meta box post type.
    if ('wanderlist-location' !== $post->post_type) {
        return $post_id;
    }
    // If we've passed all those checks, we should be good to save! Let's go.
    if (isset($_POST['wanderlist-geolocation'])) {
        $geolocation_value = sanitize_text_field($_POST['wanderlist-geolocation']);
        // Store city name, lat and long as post meta.
        $lng_value = sanitize_text_field($_POST['wanderlist-lng']);
        $lat_value = sanitize_text_field($_POST['wanderlist-lat']);
        $city_value = sanitize_text_field($_POST['wanderlist-city']);
        $region_value = sanitize_text_field($_POST['wanderlist-region']);
        // Store our country as a term in our custom "country" taxonomy.
        $country_value = sanitize_text_field($_POST['wanderlist-country']);
        // This creates a term if one doesn't already exist, or selects the existing term.
        $country_term = wp_create_term($country_value, 'wanderlist-country');
        // Make sure our term id is a string (because nobody wants to go to "148" country).
        if (is_string($country_term['term_id'])) {
            $country_term['term_id'] = (int) $country_term['term_id'];
        }
        // Remove all country associations and set our new country.
        wp_set_object_terms($post_id, $country_term['term_id'], 'wanderlist-country');
        // Update post meta.
        update_post_meta($post_id, 'wanderlist-location-string', $geolocation_value);
        update_post_meta($post_id, 'wanderlist-city', $city_value);
        update_post_meta($post_id, 'wanderlist-region', $region_value);
        update_post_meta($post_id, 'wanderlist-lat', $lat_value);
        update_post_meta($post_id, 'wanderlist-lng', $lng_value);
    } else {
        $geolocation_value = '';
        $lng_value = '';
        $lat_value = '';
        $city_value = '';
    }
    if (isset($_POST['wanderlist-arrival-date'])) {
        $arrival_date_value = sanitize_text_field($_POST['wanderlist-arrival-date']);
    } else {
        $arrival_date_value = '';
    }
    if (isset($_POST['wanderlist-departure-date'])) {
        $departure_date_value = sanitize_text_field($_POST['wanderlist-departure-date']);
    } else {
        $depature_date_value = '';
    }
    update_post_meta($post_id, 'wanderlist-arrival-date', $arrival_date_value);
    update_post_meta($post_id, 'wanderlist-departure-date', $departure_date_value);
}
Exemplo n.º 4
0
include "../wp-admin/includes/taxonomy.php";
include "adodb5/adodb.inc.php";
include "adodb5/adodb-exceptions.inc.php";
$DB = ADONewConnection($dbdriver);
# eg 'mysql' or 'postgres'
$DB->debug = false;
$DB->SetCharSet('utf8');
// for mysql
$DB->SetFetchMode(2);
// for mysql
$DB->Connect($server, $user, $password, $database);
$subjects = $DB->GetAll("SELECT * FROM `subject`");
global $wpdb;
foreach ($subjects as $subject) {
    $tag_id = $wpdb->get_var("SELECT MAX(`term_id`) FROM `wp_terms`");
    $tag = wp_create_term($subject['name']);
    echo $tag_id;
    //	$DB->query("INSERT INTO `subject_to_tag` (`subject_id`, `tag_id`) VALUES (".$subject['id'].", ".$tag_id.")");
}
$count = $DB->GetOne("SELECT COUNT(*) FROM `subject_to_tag`");
?>


<html>
<head>
<meta charset='UTF-8' />
</head>
<body>
<?php 
echo $count;
?>