• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP wp_remove_object_terms函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_removal_should_delete_object_relationship_cache

 /**
  * @ticket 34338
  */
 public function test_removal_should_delete_object_relationship_cache()
 {
     register_taxonomy('wptests_tax', 'post');
     $p = self::factory()->post->create();
     $t = self::factory()->term->create(array('taxonomy' => 'wptests_tax'));
     wp_set_object_terms($p, $t, 'wptests_tax');
     // Pollute the cache.
     get_the_terms($p, 'wptests_tax');
     wp_remove_object_terms($p, $t, 'wptests_tax');
     $this->assertFalse(get_the_terms($p, 'wptests_tax'));
 }
开发者ID:boonebgorges,项目名称:develop.wordpress,代码行数:14,代码来源:wpRemoveObjectTerms.php


示例2: test_deleted_terms_to_post_is_synced

 public function test_deleted_terms_to_post_is_synced()
 {
     $anther_term = wp_insert_term('mouse', $this->taxonomy);
     wp_set_post_terms($this->post_id, array($anther_term['term_id']), $this->taxonomy, false);
     $anther_term_2 = wp_insert_term('cat', $this->taxonomy);
     wp_set_post_terms($this->post_id, array($anther_term_2['term_id']), $this->taxonomy, true);
     wp_remove_object_terms($this->post_id, array($anther_term_2['term_id']), $this->taxonomy);
     $this->client->do_sync();
     $object_terms = get_the_terms($this->post_id, $this->taxonomy);
     $server_object_terms = $this->server_replica_storage->get_the_terms($this->post_id, $this->taxonomy);
     $server_object_terms = array_reverse($server_object_terms);
     $this->assertEquals($object_terms, $server_object_terms);
 }
开发者ID:elliott-stocks,项目名称:jetpack,代码行数:13,代码来源:test_class.jetpack-sync-terms.php


示例3: wp_update_nav_menu_item

 function wp_update_nav_menu_item($menu_id, $menu_item_db_id, $args)
 {
     $menu_lang = $this->term_translations->lang_code_by_termid($menu_id);
     $trid = $this->post_translations->get_element_trid($menu_item_db_id);
     if (array_key_exists('menu-item-type', $args) && ($args['menu-item-type'] === 'post_type' || $args['menu-item-type'] === 'taxonomy') && array_key_exists('menu-item-object-id', $args) && $menu_id > 0) {
         $language_code_item = $args['menu-item-type'] === 'post_type' ? $this->post_translations->get_element_lang_code($args['menu-item-object-id']) : $this->term_translations->lang_code_by_termid($args['menu-item-object-id']);
         $language_code_item = $language_code_item ? $language_code_item : $this->sitepress->get_current_language();
         if ($language_code_item !== $menu_lang) {
             wp_remove_object_terms((int) $menu_item_db_id, (int) $menu_id, 'nav_menu');
         }
     }
     $language_code = isset($language_code_item) && $language_code_item ? $language_code_item : ($menu_lang ? $menu_lang : $this->sitepress->get_current_language());
     $this->sitepress->set_element_language_details($menu_item_db_id, 'post_nav_menu_item', $trid, $language_code);
 }
开发者ID:aarongillett,项目名称:B22-151217,代码行数:14,代码来源:wpml-nav-menu-actions.class.php


示例4: force_change

 public function force_change()
 {
     $productShelfs = wp_get_post_terms($_REQUEST['productid'], 'product_shelf');
     if (!empty($productShelfs)) {
         foreach ($productShelfs as $productShelf) {
             wp_remove_object_terms($_REQUEST['productid'], $productShelf->term_id, 'product_shelf');
             $subarray['shelf'][$productShelf->term_id]['name'] = $productShelf->name;
             $subarray['shelf'][$productShelf->term_id]['count'] = $productShelf->count;
             $subarray['shelf'][$productShelf->term_id]['id'] = $productShelf->term_id;
         }
     }
     wp_set_post_terms($_REQUEST['productid'], $_REQUEST['wcordersortupdateshelf'], 'product_shelf', false);
     echo '<h2>Shelf Updated. <small>Please Close This POPUP</small></h2>';
     wp_die();
 }
开发者ID:technofreaky,项目名称:wc-order-category-sort,代码行数:15,代码来源:class-admin-functions.php


示例5: excludePreliminaryandMinorFromSearch

 public function excludePreliminaryandMinorFromSearch($post_id)
 {
     // only do this for TOURS or CHAPTERS
     $post = get_post($post_id);
     $post_type = $post->post_type;
     if ($post_type == 'tours' or $post_type == 'chapters') {
         //nonce checks for the meta boxes have already occured...
         if (get_post_meta($post_id, 'mb_isPreliminaryTour', true) != 'ready_to_publish_tour' or get_post_meta($post_id, 'mb_isMajorMarket', true) != 'majorMarket' or get_post_meta($post_id, 'mb_isPartnerEvent', true) != true) {
             wp_set_object_terms($post_id, 'exclude-from-search', 'category', true);
         }
         if (get_post_meta($post_id, 'mb_isPreliminaryTour', true) == 'ready_to_publish_tour' or get_post_meta($post_id, 'mb_isMajorMarket', true) == 'majorMarket' or get_post_meta($post_id, 'mb_isPartnerEvent', true) == false) {
             wp_remove_object_terms($post_id, 'exclude-from-search', 'category', true);
         }
     }
 }
开发者ID:UWAA,项目名称:uwaa-2014,代码行数:15,代码来源:Utilities.php


示例6: assign_sale_category

 /**
  * Assign/unassign the sale category after post meta was updated.
  */
 public function assign_sale_category($meta_id, $post_id, $meta_key, $meta_value)
 {
     if ($meta_key != '_price') {
         return;
         // do nothing, if the meta key is not _price
     }
     if (wp_get_post_parent_id($post_id)) {
         return;
         // bail if this is a variation
     }
     $product = wc_get_product($post_id);
     if ($product->is_on_sale()) {
         // product is on sale, let's assign the sale category
         wp_set_object_terms($post_id, $this->sale_category, 'product_cat', true);
     } else {
         // product is not on sale, let's remove the sale category
         wp_remove_object_terms($post_id, $this->sale_category, 'product_cat');
     }
 }
开发者ID:jurajk,项目名称:WooCommerce-Sale-Category,代码行数:22,代码来源:class-wc-integration-sale-category.php


示例7: test_wp_add_remove_object_terms

 /**
  * @ticket 15475
  */
 function test_wp_add_remove_object_terms()
 {
     $posts = self::$post_ids;
     $tags = self::factory()->tag->create_many(5);
     $tt = wp_add_object_terms($posts[0], $tags[1], 'post_tag');
     $this->assertEquals(1, count($tt));
     $this->assertEquals(array($tags[1]), wp_get_object_terms($posts[0], 'post_tag', array('fields' => 'ids')));
     $three_tags = array($tags[0], $tags[1], $tags[2]);
     $tt = wp_add_object_terms($posts[1], $three_tags, 'post_tag');
     $this->assertEquals(3, count($tt));
     $this->assertEquals($three_tags, wp_get_object_terms($posts[1], 'post_tag', array('fields' => 'ids')));
     $this->assertTrue(wp_remove_object_terms($posts[0], $tags[1], 'post_tag'));
     $this->assertFalse(wp_remove_object_terms($posts[0], $tags[0], 'post_tag'));
     $this->assertInstanceOf('WP_Error', wp_remove_object_terms($posts[0], $tags[1], 'non_existing_taxonomy'));
     $this->assertTrue(wp_remove_object_terms($posts[1], $three_tags, 'post_tag'));
     $this->assertEquals(0, count(wp_get_object_terms($posts[1], 'post_tag')));
     foreach ($tags as $term_id) {
         $this->assertTrue(wp_delete_term($term_id, 'post_tag'));
     }
     foreach ($posts as $post_id) {
         $this->assertTrue((bool) wp_delete_post($post_id));
     }
 }
开发者ID:pbearne,项目名称:contrib2core,代码行数:26,代码来源:term.php


示例8: wpleads_remove_lead_from_list

function wpleads_remove_lead_from_list($list_id, $lead_id)
{
    wp_remove_object_terms($lead_id, $list_id, 'wplead_list_category');
    //build meta pair for list ids lead belongs to
    $wpleads_list_ids = get_post_meta($lead_id, 'wpleads_list_ids', true);
    if ($wpleads_list_ids) {
        //get array
        $wpleads_list_ids = json_decode($wpleads_list_ids, true);
        if (!is_array($wpleads_list_ids)) {
            $wpleads_list_ids = array();
        }
        //clean
        delete_post_meta($lead_id, 'wpleads_list_ids');
        //rebuild
        foreach ($wpleads_list_ids as $key => $value) {
            if ($value['ID'] == $list_id) {
                unset($wpleads_list_ids[$key]);
            }
        }
        //store
        $wpleads_list_ids = json_encode($wpleads_list_ids);
        $wpleads_list_ids = update_post_meta($lead_id, 'wpleads_list_ids', $wpleads_list_ids);
    }
}
开发者ID:jyotiprava,项目名称:45serverbackup,代码行数:24,代码来源:module.post-type.list.php


示例9: save_module_course

 /**
  * Save module course on add/edit
  *
  * @since 1.8.0
  * @param  integer $module_id ID of module
  * @return void
  */
 public function save_module_course($module_id)
 {
     // Get module's existing courses
     $args = array('post_type' => 'course', 'post_status' => array('publish', 'draft', 'future', 'private'), 'posts_per_page' => -1, 'tax_query' => array(array('taxonomy' => $this->taxonomy, 'field' => 'id', 'terms' => $module_id)));
     $courses = get_posts($args);
     // Remove module from existing courses
     if (isset($courses) && is_array($courses)) {
         foreach ($courses as $course) {
             wp_remove_object_terms($course->ID, $module_id, $this->taxonomy);
         }
     }
     // Add module to selected courses
     if (isset($_POST['module_courses']) && is_array($_POST['module_courses']) && count($_POST['module_courses']) > 0) {
         foreach ($_POST['module_courses'] as $k => $course_id) {
             wp_set_object_terms($course_id, $module_id, $this->taxonomy, true);
         }
     }
 }
开发者ID:drumchannel,项目名称:drumchannel-dev,代码行数:25,代码来源:class-sensei-modules.php


示例10: save

 /**
  * Save settings
  */
 public function save()
 {
     global $current_section, $post;
     if ($current_section != '') {
         if (isset($_REQUEST['id'])) {
             $current_id = empty($_REQUEST['id']) ? '' : sanitize_title($_REQUEST['id']);
             switch ($current_section) {
                 // With heirarchy
                 case "property-type":
                 case "commercial-property-type":
                 case "location":
                     // TODO: Validate (check for blank fields)
                     if ($current_id == '') {
                         // Adding new term
                         // TODO: Check term doesn't exist already
                         wp_insert_term($_POST[$_POST['taxonomy'] . '_name'], $_POST['taxonomy'], array('parent' => $_POST['parent_' . $_POST['taxonomy'] . '_id']));
                         // TODO: Check for errors returned from wp_insert_term()
                     } else {
                         // Editing term
                         wp_update_term($current_id, $_POST['taxonomy'], array('name' => $_POST[$_POST['taxonomy'] . '_name'], 'parent' => $_POST['parent_' . $_POST['taxonomy'] . '_id']));
                         // TODO: Check for errors returned from wp_update_term()
                     }
                     break;
                     // Without heirarchy
                 // Without heirarchy
                 case "availability":
                 case "outside-space":
                 case "parking":
                 case "price-qualifier":
                 case "sale-by":
                 case "tenure":
                 case "commercial-tenure":
                 case "furnished":
                 case "marketing-flag":
                     // TODO: Validate (check for blank fields)
                     if ($current_id == '') {
                         // Adding new term
                         // TODO: Check term doesn't exist already
                         wp_insert_term($_POST[$_POST['taxonomy'] . '_name'], $_POST['taxonomy']);
                         // TODO: Check for errors returned from wp_insert_term()
                     } else {
                         // Editing term
                         wp_update_term($current_id, $_POST['taxonomy'], array('name' => $_POST[$_POST['taxonomy'] . '_name']));
                         // TODO: Check for errors returned from wp_update_term()
                     }
                     break;
                 case "availability-delete":
                 case "property-type-delete":
                 case "commercial-property-type-delete":
                 case "location-delete":
                 case "parking-delete":
                 case "price-qualifier-delete":
                 case "sale-by-delete":
                 case "tenure-delete":
                 case "furnished-delete":
                 case "marketing-flag-delete":
                     if (isset($_POST['confirm_removal']) && $_POST['confirm_removal'] == '1') {
                         $term_ids = explode("-", $current_id);
                         foreach ($term_ids as $current_id) {
                             // Update properties that have this taxonomy term set
                             $query_args = array('post_type' => 'property', 'nopaging' => true, 'post_status' => array('pending', 'auto-draft', 'draft', 'private', 'publish', 'future', 'trash'), 'tax_query' => array(array('taxonomy' => $_POST['taxonomy'], 'field' => 'id', 'terms' => $current_id)));
                             $property_query = new WP_Query($query_args);
                             if ($property_query->have_posts()) {
                                 while ($property_query->have_posts()) {
                                     $property_query->the_post();
                                     wp_remove_object_terms($post->ID, $current_id, $_POST['taxonomy']);
                                     // Re-assign to another term
                                     if (isset($_POST['reassign_to_' . $current_id]) && !empty($_POST['reassign_to_' . $current_id]) && $_POST['reassign_to_' . $current_id] != 'none') {
                                         $new_id = $_POST['reassign_to_' . $current_id];
                                         wp_set_post_terms($post->ID, $new_id, $_POST['taxonomy'], TRUE);
                                         // TODO: Check for WP_ERROR
                                     }
                                 }
                             }
                             wp_reset_postdata();
                             if ($_POST['taxonomy'] == 'property_type' || $_POST['taxonomy'] == 'commercial_property_type' || $_POST['taxonomy'] == 'location') {
                                 $query_args = array('post_type' => 'contact', 'nopaging' => true, 'post_status' => array('pending', 'auto-draft', 'draft', 'private', 'publish', 'future', 'trash'), 'meta_query' => array(array('key' => '_contact_types', 'value' => 'applicant', 'compare' => 'LIKE')));
                                 $applicant_query = new WP_Query($query_args);
                                 if ($applicant_query->have_posts()) {
                                     while ($applicant_query->have_posts()) {
                                         $applicant_query->the_post();
                                         $num_applicant_profiles = get_post_meta(get_the_ID(), '_applicant_profiles', TRUE);
                                         if ($num_applicant_profiles == '') {
                                             $num_applicant_profiles = 0;
                                         }
                                         if ($num_applicant_profiles > 0) {
                                             for ($i = 0; $i < $num_applicant_profiles; ++$i) {
                                                 $applicant_profile = get_post_meta(get_the_ID(), '_applicant_profile_' . $i, TRUE);
                                                 if (isset($applicant_profile[$_POST['taxonomy'] . 's']) && is_array($applicant_profile[$_POST['taxonomy'] . 's']) && !empty($applicant_profile[$_POST['taxonomy'] . 's'])) {
                                                     if (in_array($current_id, $applicant_profile[$_POST['taxonomy'] . 's'])) {
                                                         // This profile has this term set
                                                         unset($applicant_profile[$_POST['taxonomy'] . 's'][$current_id]);
                                                         if (isset($_POST['reassign_to_' . $current_id]) && !empty($_POST['reassign_to_' . $current_id]) && $_POST['reassign_to_' . $current_id] != 'none') {
                                                             $applicant_profile[$_POST['taxonomy'] . 's'][] = $_POST['reassign_to_' . $current_id];
                                                             $applicant_profile[$_POST['taxonomy'] . 's'] = array_unique($applicant_profile[$_POST['taxonomy'] . 's']);
                                                         }
                                                         $applicant_profile[$_POST['taxonomy'] . 's'] = array_values($applicant_profile[$_POST['taxonomy'] . 's']);
//.........这里部分代码省略.........
开发者ID:propertyhive,项目名称:WP-Property-Hive,代码行数:101,代码来源:class-ph-settings-custom-fields.php


示例11: wpml_remove_terms_from_post

 /**
  * Ajax handler allowing for the removal of a term from a post.
  * todo: handle the return of this in js.
  */
 public static function wpml_remove_terms_from_post()
 {
     $translated_post_id = false;
     $terms = array();
     $taxonomy = false;
     $arg_type = 'strings';
     $result = false;
     if (isset($_POST['wpml_terms'])) {
         $terms = $_POST['wpml_terms'];
     }
     if (isset($_POST['wpml_arg_type'])) {
         $arg_type = $_POST['wpml_arg_type'];
     }
     if (isset($_POST['wpml_taxonomy'])) {
         $taxonomy = $_POST['wpml_taxonomy'];
     }
     if (isset($_POST['wpml_post_id'])) {
         $translated_post_id = $_POST['wpml_post_id'];
     }
     if ($arg_type == 'strings' && !empty($terms)) {
         $result = wp_remove_object_terms($translated_post_id, $terms, $taxonomy);
     } elseif ($arg_type == 'id' && !empty($terms)) {
         $result = wp_remove_object_terms($translated_post_id, array((int) $terms), $taxonomy);
     }
     wp_send_json_success($result);
 }
开发者ID:StudioCreate,项目名称:Uncle-Hummer-WordPress-Theme,代码行数:30,代码来源:wpml-post-edit-ajax.class.php


示例12: wp_set_object_terms

/**
 * Create Term and Taxonomy Relationships.
 *
 * 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).
 *
 * A relationship means that the term is grouped in or belongs to the taxonomy.
 * A term has no meaning until it is given context by defining which taxonomy it
 * exists under.
 *
 * @since 2.3.0
 *
 * @global wpdb $wpdb The WordPress database abstraction object.
 *
 * @param int              $object_id The object to relate to.
 * @param array|int|string $terms     A single term slug, single term id, or array of either term slugs or ids.
 *                                    Will replace all existing related terms in this taxonomy.
 * @param string           $taxonomy  The context in which to relate the term to the object.
 * @param bool             $append    Optional. If false will delete difference of terms. Default false.
 * @return array|WP_Error Affected Term IDs.
 */
function wp_set_object_terms($object_id, $terms, $taxonomy, $append = false)
{
    global $wpdb;
    $object_id = (int) $object_id;
    if (!taxonomy_exists($taxonomy)) {
        return new WP_Error('invalid_taxonomy', __('Invalid taxonomy'));
    }
    if (!is_array($terms)) {
        $terms = array($terms);
    }
    if (!$append) {
        $old_tt_ids = wp_get_object_terms($object_id, $taxonomy, array('fields' => 'tt_ids', 'orderby' => 'none'));
    } else {
        $old_tt_ids = array();
    }
    $tt_ids = array();
    $term_ids = array();
    $new_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;
            }
            $term_info = wp_insert_term($term, $taxonomy);
        }
        if (is_wp_error($term_info)) {
            return $term_info;
        }
        $term_ids[] = $term_info['term_id'];
        $tt_id = $term_info['term_taxonomy_id'];
        $tt_ids[] = $tt_id;
        if ($wpdb->get_var($wpdb->prepare("SELECT term_taxonomy_id FROM {$wpdb->term_relationships} WHERE object_id = %d AND term_taxonomy_id = %d", $object_id, $tt_id))) {
            continue;
        }
        /**
         * Fires immediately before an object-term relationship is added.
         *
         * @since 2.9.0
         *
         * @param int $object_id Object ID.
         * @param int $tt_id     Term taxonomy ID.
         */
        do_action('add_term_relationship', $object_id, $tt_id);
        $wpdb->insert($wpdb->term_relationships, array('object_id' => $object_id, 'term_taxonomy_id' => $tt_id));
        /**
         * Fires immediately after an object-term relationship is added.
         *
         * @since 2.9.0
         *
         * @param int $object_id Object ID.
         * @param int $tt_id     Term taxonomy ID.
         */
        do_action('added_term_relationship', $object_id, $tt_id);
        $new_tt_ids[] = $tt_id;
    }
    if ($new_tt_ids) {
        wp_update_term_count($new_tt_ids, $taxonomy);
    }
    if (!$append) {
        $delete_tt_ids = array_diff($old_tt_ids, $tt_ids);
        if ($delete_tt_ids) {
            $in_delete_tt_ids = "'" . implode("', '", $delete_tt_ids) . "'";
            $delete_term_ids = $wpdb->get_col($wpdb->prepare("SELECT tt.term_id FROM {$wpdb->term_taxonomy} AS tt WHERE tt.taxonomy = %s AND tt.term_taxonomy_id IN ({$in_delete_tt_ids})", $taxonomy));
            $delete_term_ids = array_map('intval', $delete_term_ids);
            $remove = wp_remove_object_terms($object_id, $delete_term_ids, $taxonomy);
            if (is_wp_error($remove)) {
                return $remove;
            }
        }
    }
    $t = get_taxonomy($taxonomy);
    if (!$append && isset($t->sort) && $t->sort) {
        $values = array();
        $term_order = 0;
//.........这里部分代码省略.........
开发者ID:n8maninger,项目名称:WordPress,代码行数:101,代码来源:taxonomy-functions.php


示例13: delete_item

 /**
  * Remove a term from a post.
  *
  * @param WP_REST_Request $request Full details about the request
  * @return WP_Error|null
  */
 public function delete_item($request)
 {
     $post = get_post(absint($request['post_id']));
     $term_id = absint($request['term_id']);
     $force = isset($request['force']) ? (bool) $request['force'] : false;
     // We don't support trashing for this type, error out
     if (!$force) {
         return new WP_Error('rest_trash_not_supported', __('Terms do not support trashing.'), array('status' => 501));
     }
     $is_request_valid = $this->validate_request($request);
     if (is_wp_error($is_request_valid)) {
         return $is_request_valid;
     }
     $previous_item = $this->get_item($request);
     $remove = wp_remove_object_terms($post->ID, $term_id, $this->taxonomy);
     if (is_wp_error($remove)) {
         return $remove;
     }
     /**
      * Fires after a term is removed from a post via the REST API.
      *
      * @param array           $previous_item The removed term data.
      * @param WP_Post         $post          The post the term was removed from.
      * @param WP_REST_Request $request       The request sent to the API.
      */
     do_action('rest_remove_term', $previous_item, $post, $request);
     return $previous_item;
 }
开发者ID:deepaksinghdhanik,项目名称:ng-wp,代码行数:34,代码来源:class-wp-rest-posts-terms-controller.php


示例14: bp_remove_object_terms

/**
 * Remove taxonomy terms on a BuddyPress object.
 *
 * @since BuddyPress (2.3.0)
 *
 * @see wp_remove_object_terms() for a full description of function and parameters.
 *
 * @param int          $object_id Object ID.
 * @param string|array $terms     Term or terms to remove.
 * @param string       $taxonomy  Taxonomy name.
 *
 * @return bool|WP_Error True on success, false or WP_Error on failure.
 */
function bp_remove_object_terms($object_id, $terms, $taxonomy)
{
    $is_root_blog = bp_is_root_blog();
    if (!$is_root_blog) {
        switch_to_blog(bp_get_root_blog_id());
    }
    $retval = wp_remove_object_terms($object_id, $terms, $taxonomy);
    if (!$is_root_blog) {
        restore_current_blog();
    }
    return $retval;
}
开发者ID:AceMedia,项目名称:BuddyPress,代码行数:25,代码来源:bp-core-taxonomy.php


示例15: removeFrom

 public function removeFrom($bean)
 {
     $terms = $this->get();
     if (!is_array($bean)) {
         $bean = array($bean);
     }
     foreach ($bean as $postID) {
         wp_remove_object_terms($postID, $terms, $this->name);
     }
 }
开发者ID:Page-Carbajal,项目名称:WPExpress-Query,代码行数:10,代码来源:Taxonomy.class.php


示例16: remove_term

 /**
  * Remove a post term.
  *
  * @param  Term $term .
  * @return bool|WP_Error True on success, false or WP_Error on failure.
  */
 public function remove_term($term)
 {
     return wp_remove_object_terms($this->get_id(), $term->get_id(), $term->get_taxonomy());
 }
开发者ID:CAYdenberg,项目名称:wordpress-objects,代码行数:10,代码来源:Post.php


示例17: 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


示例18: remove_status

 public function remove_status($status_id = 0)
 {
     $update = wp_remove_object_terms($this->ID, (int) $status_id, self::STATUS_TAXONOMY);
     return $update;
 }
开发者ID:danielbachhuber,项目名称:marcgratch.com,代码行数:5,代码来源:Client.php


示例19: sync_post_and_taxonomy_terms_language

 /**
  * @param             $post_id
  * @param             $taxonomy
  * @param bool        $automatic_translation
  * Synchronizes a posts taxonomy term's languages with the posts language for all translations of the post.
  *
  */
 public static function sync_post_and_taxonomy_terms_language($post_id, $taxonomy, $automatic_translation = false)
 {
     global $sitepress;
     $post = get_post($post_id);
     $post_type = $post->post_type;
     $post_trid = $sitepress->get_element_trid($post_id, 'post_' . $post_type);
     $post_translations = $sitepress->get_element_translations($post_trid, 'post_' . $post_type);
     $terms_from_original_post = wp_get_post_terms($post_id, $taxonomy);
     $is_original = true;
     if ($sitepress->get_original_element_id($post_id, 'post_' . $post_type) != $post_id) {
         $is_original = false;
     }
     foreach ($post_translations as $post_language => $translated_post) {
         $translated_post_id = $translated_post->element_id;
         $terms_from_translated_post = wp_get_post_terms($translated_post_id, $taxonomy);
         if ($is_original) {
             /** @var $iclTranslationManagement TranslationManagement */
             global $iclTranslationManagement;
             $duplicates = $iclTranslationManagement->get_duplicates($post_id);
             if (in_array($translated_post_id, $duplicates)) {
                 $terms = array_merge($terms_from_original_post, $terms_from_translated_post);
             } else {
                 $terms = $terms_from_translated_post;
             }
         } else {
             $terms = $terms_from_translated_post;
         }
         foreach ((array) $terms as $term) {
             $term_original_tax_id = $term->term_taxonomy_id;
             $original_term_language_object = $sitepress->get_element_language_details($term_original_tax_id, 'tax_' . $term->taxonomy);
             if ($original_term_language_object && isset($original_term_language_object->language_code)) {
                 $original_term_language = $original_term_language_object->language_code;
             } else {
                 $original_term_language = $post_language;
             }
             if ($original_term_language != $post_language) {
                 $term_trid = $sitepress->get_element_trid($term_original_tax_id, 'tax_' . $term->taxonomy);
                 $translated_terms = $sitepress->get_element_translations($term_trid, 'tax_' . $term->taxonomy, false, false, true);
                 $term_id = $term->term_id;
                 wp_remove_object_terms($translated_post_id, (int) $term_id, $taxonomy);
                 if (isset($translated_terms[$post_language])) {
                     $term_in_correct_language = $translated_terms[$post_language];
                 } else {
                     $term_in_correct_language = false;
                     if ($automatic_translation) {
                         $automatic_translation_args = array('lang_code' => $post_language, 'taxonomy' => $taxonomy, 'trid' => $term_trid, 'source_language' => $original_term_language);
                         $term_in_correct_language = self::create_automatic_translation($automatic_translation_args);
                     }
                     if (!is_array($term_in_correct_language) || !isset($term_in_correct_language['term_id'])) {
                         continue;
                     }
                     $term_in_correct_language = get_term($term_in_correct_language['term_id'], $taxonomy);
                 }
                 wp_set_post_terms($translated_post_id, array((int) $term_in_correct_language->term_id), $taxonomy, true);
                 if (isset($term->term_taxonomy_id)) {
                     wp_update_term_count($term->term_taxonomy_id, $taxonomy);
                 }
             }
             wp_update_term_count($term_original_tax_id, $taxonomy);
         }
         self::sync_parent_child_relations($taxonomy, $post_language);
     }
 }
开发者ID:StudioCreate,项目名称:Uncle-Hummer-WordPress-Theme,代码行数:70,代码来源:wpml-term-translations.class.php


示例20: sync_post_and_taxonomy_terms_language

 /**
  * @param             $post_id
  * @param             $taxonomy
  * Synchronizes a posts taxonomy term's languages with the posts language for all translations of the post.
  *
  */
 public static function sync_post_and_taxonomy_terms_language($post_id, $taxonomy)
 {
     global $sitepress;
     $post = get_post($post_id);
     $post_type = $post->post_type;
     $post_trid = $sitepress->get_element_trid($post_id, 'post_' . $post_type);
     $post_translations = $sitepress->get_element_translations($post_trid, 'post_' . $post_type);
     $terms_from_original_post = wp_get_post_terms($post_id, $taxonomy);
     $is_original = true;
     if ($sitepress->get_original_element_id($post_id, 'post_' . $post_type) != $post_id) {
         $is_original = false;
     }
     foreach ($post_translations as $post_language => $translated_post) {
         $translated_post_id = $translated_post->element_id;
         if (!$translated_post_id) {
             continue;
         }
         $terms_from_translated_post = wp_get_post_terms($translated_post_id, $taxonomy);
         if ($is_original) {
             $duplicates = $sitepress->get_duplicates($post_id);
             if (in_array($translated_post_id, $duplicates)) {
                 $terms = array_merge($terms_from_original_post, $terms_from_translated_post);
             } else {
                 $terms = $terms_from_translated_post;
             }
         } else {
             $terms = $terms_from_translated_post;
         }
         foreach ((array) $terms as $term) {
             $term_original_tax_id = $term->term_taxonomy_id;
             $original_term_language_object = $sitepress->get_element_language_details($term_original_tax_id, 'tax_' . $term->taxonomy);
             if ($original_term_language_object && isset($original_term_language_object->language_code)) {
                 $original_term_language = $original_term_language_object->language_code;
             } else {
                 $original_term_language = $post_language;
             }
             if ($original_term_language != $post_language) {
                 $term_trid = $sitepress->get_element_trid($term_original_tax_id, 'tax_' . $term->taxonomy);
                 $translated_terms = $sitepress->get_element_translations($term_trid, 'tax_' . $term->taxonomy, false, false, true);
                 $term_id = $term->term_id;
                 wp_remove_object_terms($translated_post_id, (int) $term_id, $taxonomy);
                 if (isset($translated_terms[$post_language])) {
                     $term_in_correct_language = $translated_terms[$post_language];
                     wp_set_post_terms($translated_post_id, array((int) $term_in_correct_language->term_id), $taxonomy, true);
                 }
                 if (isset($term->term_taxonomy_id)) {
                     wp_update_term_count($term->term_taxonomy_id, $taxonomy);
                 }
             }
             wp_update_term_count($term_original_tax_id, $taxonomy);
         }
     }
 }
开发者ID:studiopengpeng,项目名称:ASCOMETAL,代码行数:59,代码来源:wpml-term-translations.class.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP wp_replace_in_html_tags函数代码示例发布时间:2022-05-23
下一篇:
PHP wp_removable_query_args函数代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap