本文整理汇总了PHP中wp_remove_object_terms函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_remove_object_terms函数的具体用法?PHP wp_remove_object_terms怎么用?PHP wp_remove_object_terms使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_remove_object_terms函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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'));
}
示例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);
}
示例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);
}
示例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();
}
示例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);
}
}
}
示例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');
}
}
示例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));
}
}
示例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);
}
}
示例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);
}
}
}
示例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']);
//.........这里部分代码省略.........
示例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);
}
示例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;
//.........这里部分代码省略.........
示例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;
}
示例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;
}
示例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);
}
}