当前位置: 首页>>代码示例>>PHP>>正文


PHP wp_update_term_count函数代码示例

本文整理汇总了PHP中wp_update_term_count函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_update_term_count函数的具体用法?PHP wp_update_term_count怎么用?PHP wp_update_term_count使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了wp_update_term_count函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: update_count

 public function update_count()
 {
     wp_update_term_count($this->term_taxonomy_id, 'language');
     // posts count
     wp_update_term_count($this->tl_term_taxonomy_id, 'term_language');
     // terms count
 }
开发者ID:MaryMaffka,项目名称:dpm,代码行数:7,代码来源:language.php

示例2: update_for_post

 public function update_for_post($post_id)
 {
     $taxonomies = get_taxonomies();
     foreach ($taxonomies as $taxonomy) {
         $terms_for_post = wp_get_post_terms($post_id, $taxonomy);
         foreach ($terms_for_post as $term) {
             if (isset($term->term_taxonomy_id)) {
                 wp_update_term_count($term->term_taxonomy_id, $taxonomy);
             }
         }
     }
 }
开发者ID:aarongillett,项目名称:B22-151217,代码行数:12,代码来源:class-wpml-update-term-count.php

示例3: quick_edited_post_terms

 /**
  * @param int    $post_id
  * @param string $taxonomy
  * @param array  $changed_ttids
  * @param bool   $bulk
  * Running this function will remove certain issues arising out of bulk adding of terms to posts of various languages.
  * This case can result in situations in which the WP Core functionality adds a term to a post, before the language assignment
  * operations of WPML are triggered. This leads to states in which terms can be assigned to a post even though their language
  * differs from that of the post.
  * This function behaves between hierarchical and flag taxonomies. Hierarchical terms from the wrong taxonomy are simply removed
  * from the post. Flat terms are added with the same name but in the correct language.
  * For flat terms this implies either the use of the existing term or the creation of a new one.
  * This function uses wpdb queries instead of the WordPress API, it is therefore save to be run out of
  * any language setting.
  */
 public static function quick_edited_post_terms($post_id, $taxonomy, $changed_ttids = array(), $bulk = false)
 {
     global $wpdb, $sitepress, $wpml_post_translations;
     if (!$sitepress->is_translated_taxonomy($taxonomy) || !($post_lang = $wpml_post_translations->get_element_lang_code($post_id))) {
         return;
     }
     $query_for_allowed_ttids = $wpdb->prepare("SELECT element_id FROM {$wpdb->prefix}icl_translations WHERE language_code = %s AND element_type = %s", $post_lang, 'tax_' . $taxonomy);
     $allowed_ttids = $wpdb->get_col($query_for_allowed_ttids);
     $new_ttids = array();
     foreach ($changed_ttids as $ttid) {
         if (!in_array($ttid, $allowed_ttids)) {
             $wrong_term_where = array('object_id' => $post_id, 'term_taxonomy_id' => $ttid);
             if (is_taxonomy_hierarchical($taxonomy)) {
                 // Hierarchical terms are simply deleted if they land on the wrong language
                 $wpdb->delete($wpdb->term_relationships, array('object_id' => $post_id, 'term_taxonomy_id' => $ttid));
             } else {
                 /* Flat taxonomy terms could also be given via their names and not their ttids
                  * In this case we append the ttids resulting from these names to the $changed_ttids array,
                  * we do this only in the case of these terms actually being present in another but the
                  * posts' language.
                  */
                 $query_for_term_name = $wpdb->prepare("SELECT t.name FROM {$wpdb->terms} AS t JOIN {$wpdb->term_taxonomy} AS tt ON t.term_id = tt.term_id WHERE tt.term_taxonomy_id=%d", $ttid);
                 $term_name = $wpdb->get_var($query_for_term_name);
                 $ttid_in_correct_lang = false;
                 if (!empty($allowed_ttids)) {
                     $in = wpml_prepare_in($allowed_ttids, "%d");
                     // Try to get the ttid of a term in the correct language, that has the same
                     $ttid_in_correct_lang = $wpdb->get_var($wpdb->prepare("SELECT tt.term_taxonomy_id\n\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\t{$wpdb->terms} AS t\n\t\t\t\t\t\t\t\tJOIN {$wpdb->term_taxonomy} AS tt\n\t\t\t\t\t\t\t\t\tON t.term_id = tt.term_id\n\t\t\t\t\t\t\tWHERE t.name=%s AND tt.taxonomy=%s AND tt.term_taxonomy_id IN ({$in})", $term_name, $taxonomy));
                 }
                 if (!$ttid_in_correct_lang) {
                     /* If we do not have a term by this name in the given taxonomy and language we have to create it.
                      * In doing so we must avoid interactions with filtering by wpml on this functionality and ensure uniqueness for the slug of the newly created term.
                      */
                     $new_term = wp_insert_term($term_name, $taxonomy, array('slug' => self::term_unique_slug(sanitize_title($term_name), $taxonomy, $post_lang)));
                     if (isset($new_term['term_taxonomy_id'])) {
                         $ttid_in_correct_lang = $new_term['term_taxonomy_id'];
                         $trid = $bulk ? $sitepress->get_element_trid($ttid, 'tax_' . $taxonomy) : false;
                         $sitepress->set_element_language_details($ttid_in_correct_lang, 'tax_' . $taxonomy, $trid, $post_lang);
                     }
                 }
                 if (!in_array($ttid_in_correct_lang, $changed_ttids)) {
                     $wpdb->update($wpdb->term_relationships, array('term_taxonomy_id' => $ttid_in_correct_lang), $wrong_term_where);
                     $new_ttids[] = $ttid_in_correct_lang;
                 } else {
                     $wpdb->delete($wpdb->term_relationships, array('object_id' => $post_id, 'term_taxonomy_id' => $ttid));
                 }
             }
         }
     }
     // Update term counts manually here, since using sql, will not trigger the updating of term counts automatically.
     wp_update_term_count(array_merge($changed_ttids, $new_ttids), $taxonomy);
 }
开发者ID:studiopengpeng,项目名称:ASCOMETAL,代码行数:67,代码来源:wpml-term-translations.class.php

示例4: remove_object_terms

 /**
  * Remove term(s) associated with a given object(s). Core doesn't have this as of 3.2
  * @see http://core.trac.wordpress.org/ticket/15475
  * 
  * @author ericmann
  * @compat 3.3?
  *
  * @param int|array $object_ids The ID(s) of the object(s) to retrieve.
  * @param int|array $terms The ids of the terms to remove.
  * @param string|array $taxonomies The taxonomies to retrieve terms from.
  * @return bool|WP_Error Affected Term IDs
  */
 function remove_object_terms($object_id, $terms, $taxonomy)
 {
     global $wpdb;
     if (!taxonomy_exists($taxonomy)) {
         return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));
     }
     if (!is_array($object_id)) {
         $object_id = array($object_id);
     }
     if (!is_array($terms)) {
         $terms = array($terms);
     }
     $delete_objects = array_map('intval', $object_id);
     $delete_terms = array_map('intval', $terms);
     if ($delete_terms) {
         $in_delete_terms = "'" . implode("', '", $delete_terms) . "'";
         $in_delete_objects = "'" . implode("', '", $delete_objects) . "'";
         $return = $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->term_relationships} WHERE object_id IN ({$in_delete_objects}) AND term_taxonomy_id IN ({$in_delete_terms})", $object_id));
         wp_update_term_count($delete_terms, $taxonomy);
         return true;
     }
     return false;
 }
开发者ID:philoserf,项目名称:Edit-Flow,代码行数:35,代码来源:class-module.php

示例5: save_job

 /**
  * save simplyhired job
  */
 function save_job($job, $import_author)
 {
     $prefix = 'et_';
     $result = wp_insert_post(array('post_author' => $import_author != '' ? $import_author : 1, 'post_date' => date('Y-m-d 00:00:00', strtotime($job['date'])), 'post_status' => 'publish', 'post_content' => apply_filters('et_job_content', $job['description']), 'post_type' => 'job', 'post_title' => $job['title'], 'tax_input' => array('job_category' => array($job['job_category']), 'job_type' => array($job['job_type']))));
     // if insert fail, return false
     if (!$result) {
         return false;
     }
     // otherwise, insert meta data and terms
     wp_set_object_terms($result, $job['job_category'], 'job_category');
     wp_set_object_terms($result, $job['job_type'], 'job_type');
     if (defined('ALTERNATE_WP_CRON')) {
         global $wpdb;
         if ($term_info = term_exists($job['job_category'], 'job_category')) {
             $tt_id = $term_info['term_taxonomy_id'];
             $wpdb->insert($wpdb->term_relationships, array('object_id' => $result, 'term_taxonomy_id' => $tt_id));
             wp_update_term_count(array($tt_id), 'job_category');
         }
         if ($term_info = term_exists($job['job_type'], 'job_type')) {
             $tt_id = $term_info['term_taxonomy_id'];
             $wpdb->insert($wpdb->term_relationships, array('object_id' => $result, 'term_taxonomy_id' => $tt_id));
             wp_update_term_count(array($tt_id), 'job_type');
         }
     }
     update_post_meta($result, $prefix . 'simplyhired_url', $job['url']);
     update_post_meta($result, $prefix . 'template_id', 'simplyhired');
     update_post_meta($result, $prefix . 'simplyhired_creator', $job['company']);
     update_post_meta($result, $prefix . 'simplyhired_jobkey', $job['jobkey']);
     update_post_meta($result, $prefix . 'location', $job['location']);
     update_post_meta($result, $prefix . 'full_location', $job['location']);
     update_post_meta($result, $prefix . 'job_paid', 2);
     update_post_meta($result, $prefix . 'simplyhired_add_time', date('Y-m-d 00:00:00', time()));
     return true;
 }
开发者ID:linniepinski,项目名称:perssistant,代码行数:37,代码来源:simplyhired.php

示例6: edcal_changedate


//.........这里部分代码省略.........
                 * has moved that post since the page was last updated.  If the 
                 * old date in the database doesn't match the old date from the
                 * browser then we return an error to the browser along with the
                 * updated post data.
                 */
                $error = EDCAL_CONCURRENCY_ERROR;
            }
        }
        if ($error) {
            // die('error= '.$error);
            ?>
            {
                "error": <?php 
            echo $error;
            ?>
,
                "post" :
            <?php 
            $this->edcal_postJSON($post, false, true);
            ?>
 }
            
            <?php 
            die;
        }
        /*
         * No errors, so let's go create our new post parameters to update
         */
        $updated_post = array();
        $updated_post['ID'] = $edcal_postid;
        if (!$move_to_drawer) {
            $updated_post['post_date'] = $edcal_newDate . substr($post->post_date, strlen($edcal_newDate));
        }
        /*
         * When a user creates a draft and never sets a date or publishes it 
         * then the GMT date will have a timestamp of 00:00:00 to indicate 
         * that the date hasn't been set.  In that case we need to specify
         * an edit date or the wp_update_post function will strip our new
         * date out and leave the post as publish immediately.
         */
        $needsEditDate = preg_match('/^0000/', $post->post_date_gmt);
        if ($needsEditDate) {
            // echo "\r\nneeds edit date\r\n";
            $updated_post['edit_date'] = $edcal_newDate . substr($post->post_date, strlen($edcal_newDate));
        }
        if ($move_to_drawer) {
            $updated_post['post_date_gmt'] = "0000-00-00 00:00:00";
            $updated_post['edit_date'] = $post->post_date;
        } else {
            if ($move_from_drawer) {
                $updated_post['post_date_gmt'] = get_gmt_from_date($post->post_date);
                $updated_post['post_modified_gmt'] = get_gmt_from_date($post->post_date);
            }
        }
        /*
         * We need to make sure to use the GMT formatting for the date.
         */
        if (!$move_to_drawer) {
            $updated_post['post_date_gmt'] = get_gmt_from_date($updated_post['post_date']);
            $updated_post['post_modified'] = $edcal_newDate . substr($post->post_modified, strlen($edcal_newDate));
            $updated_post['post_modified_gmt'] = get_gmt_from_date($updated_post['post_date']);
        }
        if ($edcal_postStatus != $post->post_status) {
            /*
             * We only want to update the post status if it has changed.
             * If the post status has changed that takes a few more steps
             */
            wp_transition_post_status($edcal_postStatus, $post->post_status, $post);
            $updated_post['post_status'] = $edcal_postStatus;
            // Update counts for the post's terms.
            foreach ((array) get_object_taxonomies('post') as $taxonomy) {
                $tt_ids = wp_get_object_terms($post_id, $taxonomy, 'fields=tt_ids');
                wp_update_term_count($tt_ids, $taxonomy);
            }
            do_action('edit_post', $edcal_postid, $post);
            do_action('save_post', $edcal_postid, $post);
            do_action('wp_insert_post', $edcal_postid, $post);
        }
        // die(var_dump($updated_post).'success!');
        /*
         * Now we finally update the post into the database
         */
        wp_update_post($updated_post);
        /*
         * We finish by returning the latest data for the post in the JSON
         */
        global $post;
        $args = array('posts_id' => $edcal_postid);
        $post = get_post($edcal_postid);
        ?>
{
            "post" :
            
        <?php 
        $this->edcal_postJSON($post, false, true);
        ?>
}
        <?php 
        die;
    }
开发者ID:shahadat014,项目名称:geleyi,代码行数:101,代码来源:edcal.php

示例7: wp_set_object_terms

/**
 * wp_set_object_terms() - 
 * 
 * Relates an object (post, link etc) to a term and taxonomy type.  Creates the term and taxonomy
 * relationship if it doesn't already exist.  Creates a term if it doesn't exist (using the slug).
 *
 * @global $wpdb Database Object
 * @param int $object_id The object to relate to.
 * @param array|int|string $term The slug or id of the term.
 * @param array|string $taxonomy The context in which to relate the term to the object.
 * @param bool $append If false will delete difference of terms.
 */
function wp_set_object_terms($object_id, $terms, $taxonomy, $append = false) {
	global $wpdb;

	$object_id = (int) $object_id;

	if ( ! is_taxonomy($taxonomy) )
		return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));

	if ( !is_array($terms) )
		$terms = array($terms);

	if ( ! $append )
		$old_terms =  wp_get_object_terms($object_id, $taxonomy, 'fields=tt_ids');

	$tt_ids = array();
	$term_ids = array();

	foreach ($terms as $term) {
		if ( !$id = is_term($term, $taxonomy) )
			$id = wp_insert_term($term, $taxonomy);
		$term_ids[] = $id['term_id'];
		$id = $id['term_taxonomy_id'];
		$tt_ids[] = $id;

		if ( $wpdb->get_var("SELECT term_taxonomy_id FROM $wpdb->term_relationships WHERE object_id = '$object_id' AND term_taxonomy_id = '$id'") )
			continue;
		$wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES ('$object_id', '$id')");
	}

	wp_update_term_count($tt_ids, $taxonomy);

	if ( ! $append ) {
		$delete_terms = array_diff($old_terms, $tt_ids);
		if ( $delete_terms ) {
			$in_delete_terms = "'" . implode("', '", $delete_terms) . "'";
			$wpdb->query("DELETE FROM $wpdb->term_relationships WHERE object_id = '$object_id' AND term_taxonomy_id IN ($in_delete_terms)");
			wp_update_term_count($delete_terms, $taxonomy);
		}
	}

	return $tt_ids;
}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:54,代码来源:taxonomy.php

示例8: languages_page


//.........这里部分代码省略.........
                 foreach ($_POST['translation'][$language->name] as $key => $translation) {
                     $mo->add_entry($mo->make_entry($strings[$key]['string'], stripslashes($translation)));
                 }
                 // FIXME should I clean the mo object to remove unused strings ?
                 $this->mo_export($mo, $language);
             }
             $paged = isset($_GET['paged']) ? '&paged=' . $_GET['paged'] : '';
             wp_redirect('admin.php?page=mlang&tab=strings' . $paged);
             // to refresh the page (possible thanks to the $_GET['noheader']=true)
             exit;
             break;
         case 'options':
             check_admin_referer('options-lang', '_wpnonce_options-lang');
             $options['default_lang'] = $_POST['default_lang'];
             $options['rewrite'] = $_POST['rewrite'];
             foreach (array('browser', 'hide_default', 'force_lang', 'redirect_lang') as $key) {
                 $options[$key] = isset($_POST[$key]) ? 1 : 0;
             }
             update_option('polylang', $options);
             // refresh rewrite rules in case rewrite or hide_default options have been modified
             // it seems useless to refresh permastruct here
             $wp_rewrite->flush_rules();
             // fills existing posts & terms with default language
             if (isset($_POST['fill_languages'])) {
                 global $wpdb;
                 $untranslated = $this->get_untranslated();
                 $lang = $this->get_language($options['default_lang']);
                 $values = array();
                 foreach ($untranslated['posts'] as $post_id) {
                     $values[] = $wpdb->prepare("(%d, %d)", $post_id, $lang->term_taxonomy_id);
                 }
                 if ($values) {
                     $wpdb->query("INSERT INTO {$wpdb->term_relationships} (object_id, term_taxonomy_id) VALUES " . implode(',', $values));
                     wp_update_term_count($lang->term_taxonomy_id, 'language');
                     // updating term count is mandatory (thanks to AndyDeGroo)
                 }
                 $values = array();
                 foreach ($untranslated['terms'] as $term_id) {
                     $values[] = $wpdb->prepare("(%d, %s, %d)", $term_id, '_language', $lang->term_id);
                 }
                 if ($values) {
                     $wpdb->query("INSERT INTO {$wpdb->termmeta} (term_id, meta_key, meta_value) VALUES " . implode(',', $values));
                 }
             }
             break;
         default:
             break;
     }
     // prepare the list of tabs
     $tabs = array('lang' => __('Languages', 'polylang'));
     // only if at least one language has been created
     if ($listlanguages = $this->get_languages_list()) {
         if (current_theme_supports('menus')) {
             $tabs['menus'] = __('Menus', 'polylang');
         }
         // don't display the menu tab if the active theme does not support nav menus
         $tabs['strings'] = __('Strings translation', 'polylang');
         $tabs['settings'] = __('Settings', 'polylang');
     }
     $active_tab = isset($_GET['tab']) && $_GET['tab'] ? $_GET['tab'] : 'lang';
     switch ($active_tab) {
         case 'lang':
             // prepare the list table of languages
             $data = array();
             foreach ($listlanguages as $lang) {
                 $data[] = array_merge((array) $lang, array('flag' => $this->get_flag($lang)));
开发者ID:ramonvloon,项目名称:Ingrid,代码行数:67,代码来源:admin.php

示例9: save_indeed_jobs

 /**
  * Save sending job
  */
 function save_indeed_jobs($job, $author = 1)
 {
     $prefix = 'et_';
     $_POST += array('post_type' => 'job');
     $result = wp_insert_post(array('post_author' => $author, 'post_date' => date('Y-m-d h:i:s', time()), 'post_status' => 'publish', 'post_content' => $job['content'], 'post_type' => 'job', 'post_title' => $job['jobtitle'], 'tax_input' => array('job_category' => array($job['job_category']), 'job_type' => array($job['job_type']))));
     // if insert fail, return false
     if (!$result) {
         return false;
     }
     // otherwise, insert meta data and terms
     wp_set_object_terms($result, $job['job_category'], 'job_category');
     wp_set_object_terms($result, $job['job_type'], 'job_type');
     if (defined('ALTERNATE_WP_CRON')) {
         global $wpdb;
         if ($term_info = term_exists($job['job_category'], 'job_category')) {
             $tt_id = $term_info['term_taxonomy_id'];
             $wpdb->insert($wpdb->term_relationships, array('object_id' => $result, 'term_taxonomy_id' => $tt_id));
             wp_update_term_count(array($tt_id), 'job_category');
         }
         if ($term_info = term_exists($job['job_type'], 'job_type')) {
             $tt_id = $term_info['term_taxonomy_id'];
             $wpdb->insert($wpdb->term_relationships, array('object_id' => $result, 'term_taxonomy_id' => $tt_id));
             wp_update_term_count(array($tt_id), 'job_type');
         }
     }
     $meta_maps = array('location' => 'formattedLocationFull', 'full_location' => 'formattedLocationFull', 'indeed_company' => 'company', 'indeed_url' => 'url', 'indeed_city' => 'city', 'indeed_state' => 'city', 'indeed_country' => 'country', 'indeed_id' => 'jobkey');
     foreach ($meta_maps as $key => $value) {
         update_post_meta($result, $prefix . $key, $job[$value]);
     }
     update_post_meta($result, $prefix . 'template_id', 'indeed');
     return true;
 }
开发者ID:linniepinski,项目名称:perssistant,代码行数:35,代码来源:je_indeed.php

示例10: update_term_counts

 /**
  * Count terms. These are done at this point so all product props are set in advance.
  *
  * @param WC_Product
  * @since 2.7.0
  */
 protected function update_term_counts(&$product)
 {
     if (!wp_defer_term_counting()) {
         global $wc_allow_term_recount;
         $wc_allow_term_recount = true;
         $post_type = $product->is_type('variation') ? 'product_variation' : 'product';
         // Update counts for the post's terms.
         foreach ((array) get_object_taxonomies($post_type) as $taxonomy) {
             $tt_ids = wc_get_object_terms($product->get_id(), $taxonomy, 'term_taxonomy_id');
             wp_update_term_count($tt_ids, $taxonomy);
         }
     }
 }
开发者ID:shivapoudel,项目名称:woocommerce,代码行数:19,代码来源:class-wc-product-data-store-cpt.php

示例11: recount

 /**
  * Recalculate number of posts assigned to each term.
  *
  * In instances where manual updates are made to the terms assigned to
  * posts in the database, the number of posts associated with a term
  * can become out-of-sync with the actual number of posts.
  *
  * This command runs wp_update_term_count() on the taxonomy's terms
  * to bring the count back to the correct value.
  *
  * ## OPTIONS
  *
  * <taxonomy>...
  * : One or more taxonomies to recalculate.
  *
  * ## EXAMPLES
  *
  *     wp term recount category post_tag
  *
  *     wp taxonomy list --field=name | xargs wp term recount
  */
 public function recount($args)
 {
     foreach ($args as $taxonomy) {
         if (!taxonomy_exists($taxonomy)) {
             WP_CLI::warning(sprintf("Taxonomy %s does not exist.", $taxonomy));
         } else {
             $terms = get_terms($taxonomy, array('hide_empty' => false));
             $term_taxonomy_ids = wp_list_pluck($terms, 'term_taxonomy_id');
             wp_update_term_count($term_taxonomy_ids, $taxonomy);
             WP_CLI::success(sprintf("Updated %s term count", $taxonomy));
         }
     }
 }
开发者ID:wesm87,项目名称:wp-cli,代码行数:34,代码来源:term.php

示例12: wp_remove_object_terms

 /**
  * Remove term(s) associated with a given object.
  *
  *
  * @global wpdb $wpdb WordPress database abstraction object.
  *
  * @param int $object_id The ID of the object from which the terms will be removed.
  * @param array|int|string $terms The slug(s) or ID(s) of the term(s) to remove.
  * @param array|string $taxonomy Taxonomy name.
  * @return bool|WP_Error True on success, false or WP_Error on failure.
  */
 private static function wp_remove_object_terms($object_id, $terms, $taxonomy)
 {
     global $wpdb;
     // Remove notices in below 3.6 and support backwards compatibility
     if (function_exists('wp_remove_object_terms')) {
         return wp_remove_object_terms($object_id, $terms, $taxonomy);
     }
     $object_id = (int) $object_id;
     if (!taxonomy_exists($taxonomy)) {
         return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));
     }
     if (!is_array($terms)) {
         $terms = array($terms);
     }
     $tt_ids = array();
     foreach ((array) $terms as $term) {
         if (!strlen(trim($term))) {
             continue;
         }
         if (!($term_info = term_exists($term, $taxonomy))) {
             // Skip if a non-existent term ID is passed.
             if (is_int($term)) {
                 continue;
             }
         }
         if (is_wp_error($term_info)) {
             return $term_info;
         }
         $tt_ids[] = $term_info['term_taxonomy_id'];
     }
     if ($tt_ids) {
         $in_tt_ids = "'" . implode("', '", $tt_ids) . "'";
         /**
          * Fires immediately before an object-term relationship is deleted.
          *
          * @since 2.9.0
          *
          * @param int   $object_id Object ID.
          * @param array $tt_ids    An array of term taxonomy IDs.
          */
         do_action('delete_term_relationships', $object_id, $tt_ids);
         $deleted = $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->term_relationships} WHERE object_id = %d AND term_taxonomy_id IN ({$in_tt_ids})", $object_id));
         /**
          * Fires immediately after an object-term relationship is deleted.
          *
          * @since 2.9.0
          *
          * @param int   $object_id Object ID.
          * @param array $tt_ids    An array of term taxonomy IDs.
          */
         do_action('deleted_term_relationships', $object_id, $tt_ids);
         wp_update_term_count($tt_ids, $taxonomy);
         return (bool) $deleted;
     }
     return false;
 }
开发者ID:rohmann,项目名称:wp-cli,代码行数:67,代码来源:CommandWithTerms.php

示例13: jr_check_expired_cron

function jr_check_expired_cron()
{
    global $wpdb;
    $action = get_option('jr_expired_action');
    // Get list of expired posts that are published
    $postids = $wpdb->get_col($wpdb->prepare("\n\t\tSELECT      postmeta.post_id\n\t\tFROM        {$wpdb->postmeta} postmeta\n\t\tLEFT JOIN\t{$wpdb->posts} posts ON postmeta.post_id = posts.ID\n\t\tWHERE       postmeta.meta_key = '_expires' \n\t\t            AND postmeta.meta_value < '%s'\n\t\t            AND post_status = 'publish'\n\t\t            AND post_type = 'job_listing'\n\t", strtotime('NOW')));
    if ($action == 'hide') {
        if ($postids) {
            foreach ($postids as $id) {
                // Captains log supplemental, we have detected a job which is out of date
                // Activate Cloak
                $post = get_post($id);
                if (empty($post)) {
                    return;
                }
                if ('private' == $post->post_status) {
                    return;
                }
                $old_status = $post->post_status;
                $job_post = array();
                $job_post['ID'] = $id;
                $job_post['post_status'] = 'private';
                wp_update_post($job_post);
                $post->post_status = 'private';
                wp_transition_post_status('private', $old_status, $post);
                // Update counts for the post's terms.
                foreach ((array) get_object_taxonomies('job_listing') as $taxonomy) {
                    $tt_ids = wp_get_object_terms($id, $taxonomy, array('fields' => 'tt_ids'));
                    wp_update_term_count($tt_ids, $taxonomy);
                }
                do_action('edit_post', $id, $post);
                do_action('save_post', $id, $post);
                do_action('wp_insert_post', $id, $post);
            }
        }
    }
    if (get_option('jr_expired_job_email_owner') == 'yes') {
        $notify_ids = array();
        // Get list of expiring posts that are published
        $postids = $wpdb->get_col($wpdb->prepare("\n\t\t\tSELECT      DISTINCT postmeta.post_id\n\t\t\tFROM        {$wpdb->postmeta} postmeta\n\t\t\tLEFT JOIN\t{$wpdb->posts} posts ON postmeta.post_id = posts.ID\n\t\t\tWHERE       postmeta.meta_key = '_expires' \n\t\t\t            AND postmeta.meta_value > '%s'\n\t\t\t            AND postmeta.meta_value < '%s'\n\t\t\t            AND post_status = 'publish'\n\t\t\t            AND post_type = 'job_listing'\n\t\t", strtotime('NOW'), strtotime('+5 day')));
        if (sizeof($postids) > 0) {
            // of those, get ids of posts that have already been notified
            $jobs_notified = $wpdb->get_col($wpdb->prepare("\n\t\t\t\tSELECT      postmeta.post_id\n\t\t\t\tFROM        {$wpdb->postmeta} postmeta\n\t\t\t\tWHERE       postmeta.meta_key = 'reminder_email_sent' \n\t\t\t\t            AND postmeta.meta_value IN ('5','1')\n\t\t\t"));
            // Now only send to those who need sending to
            $notify_ids = array_diff($postids, $jobs_notified);
            if ($notify_ids && sizeof($notify_ids) > 0) {
                foreach ($notify_ids as $id) {
                    update_post_meta($id, 'reminder_email_sent', '5');
                    jr_owner_job_expiring_soon($id, 5);
                }
            }
        }
        // Get list of expiring posts (1 day left) that are published
        $postids = $wpdb->get_col($wpdb->prepare("\n\t\t\tSELECT      postmeta.post_id\n\t\t\tFROM        {$wpdb->postmeta} postmeta\n\t\t\tLEFT JOIN\t{$wpdb->posts} posts ON postmeta.post_id = posts.ID\n\t\t\tWHERE       postmeta.meta_key = '_expires' \n\t\t\t            AND postmeta.meta_value > '%s'\n\t\t\t            AND postmeta.meta_value < '%s'\n\t\t\t            AND post_status = 'publish'\n\t\t\t            AND post_type = 'job_listing'\n\t\t", strtotime('NOW'), strtotime('+1 day')));
        if (sizeof($postids) > 0) {
            // of those, get ids of posts that have already been notified
            $jobs_notified = $wpdb->get_col($wpdb->prepare("\n\t\t\t\tSELECT      postmeta.post_id\n\t\t\t\tFROM        {$wpdb->postmeta} postmeta\n\t\t\t\tWHERE       postmeta.meta_key = 'reminder_email_sent' \n\t\t\t\t            AND postmeta.meta_value IN ('1')\n\t\t\t", implode(',', $postids)));
            // Now only send to those who need sending to
            $notify_ids_2 = array_diff($postids, $jobs_notified, $notify_ids);
            if ($notify_ids_2 && sizeof($notify_ids_2) > 0) {
                foreach ($notify_ids_2 as $id) {
                    update_post_meta($id, 'reminder_email_sent', '1');
                    jr_owner_job_expiring_soon($id, 1);
                }
            }
        }
    }
}
开发者ID:besimhu,项目名称:legacy,代码行数:68,代码来源:theme-cron.php

示例14: delete_series_object_relationship

function delete_series_object_relationship($object_id, $terms)
{
    global $wpdb;
    $object_id = (int) $object_id;
    $t_ids = array();
    if (!is_array($terms)) {
        $terms = array($terms);
    }
    foreach ($terms as $term) {
        $t_obj = term_exists($term, 'series');
        if (is_object($t_obj)) {
            $t_ids[] = $t_obj->term_taxonomy_id;
        }
    }
    if (!empty($t_ids)) {
        $in_tt_ids = "'" . implode("', '", $t_ids) . "'";
        $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->term_relationships} WHERE object_id = %d AND term_taxonomy_id IN ({$in_tt_ids})", $object_id));
        wp_update_term_count($t_ids, 'series');
    }
}
开发者ID:briancfeeney,项目名称:portigal,代码行数:20,代码来源:orgSeries-taxonomy.php

示例15: edcal_changedate


//.........这里部分代码省略.........
 }
        
        <?php 
        die;
    }
    $post = get_post($edcal_postid, ARRAY_A);
    setup_postdata($post);
    /*
     * We are doing optimistic concurrency checking on the dates.  If
     * the user tries to move a post we want to make sure nobody else
     * has moved that post since the page was last updated.  If the 
     * old date in the database doesn't match the old date from the
     * browser then we return an error to the browser along with the
     * updated post data.
     */
    if (date('Y-m-d', strtotime($post['post_date'])) != date('Y-m-d', strtotime($edcal_oldDate))) {
        global $EDCAL_CONCURRENCY_ERROR;
        ?>
 {
            "error": <?php 
        echo $EDCAL_CONCURRENCY_ERROR;
        ?>
,
        <?php 
        global $post;
        $args = array('posts_id' => $edcal_postid);
        $post = get_post($edcal_postid);
        ?>
            "post" :
        <?php 
        edcal_postJSON($post, false, true);
        ?>
 }
        
        <?php 
        die;
    }
    /*
     * Posts in WordPress have more than one date.  There is the GMT date,
     * the date in the local time zone, the modified date in GMT and the
     * modified date in the local time zone.  We update all of them.
     */
    $post['post_date_gmt'] = $post['post_date'];
    /*
     * When a user creates a draft and never sets a date or publishes it 
     * then the GMT date will have a timestamp of 00:00:00 to indicate 
     * that the date hasn't been set.  In that case we need to specify
     * an edit date or the wp_update_post function will strip our new
     * date out and leave the post as publish immediately.
     */
    $needsEditDate = strpos($post['post_date_gmt'], "0000-00-00 00:00:00") === 0;
    $updated_post = array();
    $updated_post['ID'] = $edcal_postid;
    $updated_post['post_date'] = $edcal_newDate . substr($post['post_date'], strlen($edcal_newDate));
    if ($needsEditDate != -1) {
        $updated_post['edit_date'] = $edcal_newDate . substr($post['post_date'], strlen($edcal_newDate));
    }
    /*
     * We need to make sure to use the GMT formatting for the date.
     */
    $updated_post['post_date_gmt'] = get_gmt_from_date($updated_post['post_date']);
    $updated_post['post_modified'] = $edcal_newDate . substr($post['post_modified'], strlen($edcal_newDate));
    $updated_post['post_modified_gmt'] = get_gmt_from_date($updated_post['post_date']);
    if ($edcal_postStatus != $post['post_status']) {
        /*
         * We only want to update the post status if it has changed.
         * If the post status has changed that takes a few more steps
         */
        wp_transition_post_status($edcal_postStatus, $post['post_status'], $post);
        $updated_post['post_status'] = $edcal_postStatus;
        // Update counts for the post's terms.
        foreach ((array) get_object_taxonomies('post') as $taxonomy) {
            $tt_ids = wp_get_object_terms($post_id, $taxonomy, 'fields=tt_ids');
            wp_update_term_count($tt_ids, $taxonomy);
        }
        do_action('edit_post', $edcal_postid, $post);
        do_action('save_post', $edcal_postid, $post);
        do_action('wp_insert_post', $edcal_postid, $post);
    }
    /*
     * Now we finally update the post into the database
     */
    wp_update_post($updated_post);
    /*
     * We finish by returning the latest data for the post in the JSON
     */
    global $post;
    $args = array('posts_id' => $edcal_postid);
    $post = get_post($edcal_postid);
    ?>
{
        "post" :
        
    <?php 
    edcal_postJSON($post, false, true);
    ?>
}
    <?php 
    die;
}
开发者ID:niko-lgdcom,项目名称:archives,代码行数:101,代码来源:edcal.php


注:本文中的wp_update_term_count函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。