wp_set_object_terms doesn't work on 1.7, but it does on 1.6.6.4
-
The following code works when I use the Version 1.6.6.4, but not with 1.7… Please fix.
wp_set_object_terms($post_id, (array)(int)$country, ‘country’);
-
Dear yflor3
I suppose it works whit WP 4.1.x but not with 4.2.x.
Could you test Types 1.7.1 with WordPress 4.1?
Cheers,
MarcinI have WP 4.2.2. I tried types version 1.7.2 and still not working.
I have to go back to Types version 1.6.6.4 for it to work.Dear yflor3
I try to reproduce this issue.
Please tell me, when you call this? Could you past code with action/filter trigger?
Marcin
I call the code when the user is submitting/ uploading a post from a front end uploader.
This is part of the code I have on my footer file:
<div class="modal-top-wrap"> <div class="halfpost"> <div class="append"><?php _e('Type', 'Aruna');?></div> <select class="post_type" name="post_type" id="myCombobox"> <option value="window-image" selected><?php _e('Image Post', 'Aruna');?></option> <option value="window-slider"><?php _e('Slider Post', 'Aruna');?></option> <option value="window-video"><?php _e('Video Post', 'Aruna');?></option> </select> </div> <div class="halfpost category-combobox"> <div class="append"><?php _e('Category', 'Aruna');?></div> <select name="post_category" id="categoryCombobox"> <?php $categories = get_categories('hide_empty=0'); foreach($categories as $category) { $id = $category->term_id; $name = $category->name; ?> <option id="category_<?php echo $id;?>_bg" value="<?php echo $id;?>"><?php echo $name;?></option> <?php } ?> </select> <div class="append"><?php _e('Country', 'Aruna');?></div> <select name="post_country" id="categoryCombobox"> <?php $countries = get_terms( "country", array('hide_empty' => 0,) ); foreach($countries as $country) { $id = $country->term_id; $name = $country->name; ?> <option id="category_<?php echo $id;?>_bg" value="<?php echo $id;?>"><?php echo $name;?></option> <?php } ?> </select> </div> </div>
This part of the code I have on my function file:
$country = $_POST['post_country'];
more code//setting country wp_set_object_terms($post_id, (array)(int)$country, 'country');
I’m sorry, but I have to less information to help ??
M
Same issue here.
I’m running Types 1.7.7 and WP 4.2.2
I have custom taxonomies create in Types and post form processors that I wrote both in functions.php, and in their own plugin files. The processors are hooked into
init
.The posts come through fine, but they don’t get the tax associated with them. I get an “Invalid Taxonomy” error. I’ve tried it on two separate installs with different taxonomies, with the same result.
Here’s some sample code:
function process_classified_form() { global $user_ID; global $current_user; $postTitle = $_POST['post_title']; $post = $_POST['post_content']; // Paramters for new post based on form data $new_post = array( 'post_title' => $postTitle, 'post_content' => $post, 'post_status' => 'publish', 'comment_status' => 'closed', 'post_author' => $user_ID, 'post_type' => 'classifieds' ); // Insert new post and assign new ID to variable $newPostID = wp_insert_post( $new_post ); // Get the permalink $classified_permalink = get_permalink( $newPostID ); // Add Custom Taxonomy from Dropdown Menu $postSection = $_POST['post_section']; wp_set_object_terms( $newPostID, $postSection, 'section', true ); return $classified_permalink; } add_action( 'init', 'classified_processing' ); function classified_processing() { if( isset( $_POST['classified-submit'] ) ) { $newlink = process_classified_form(); wp_redirect( $newlink ); exit; } }
This morning I deactivated my custom taxonomy in Types and replaced it with the standalone function to get it registered.
That solved my problem, so it looks like there’s something happening in Types that’s not registering it correctly. Or perhaps not at the right time?
- The topic ‘wp_set_object_terms doesn't work on 1.7, but it does on 1.6.6.4’ is closed to new replies.