This topic contains 8 reply and 4 voices, and was last updated by Rogier 5 years, 7 months ago
Viewing 8 Posts - 1 through 8 (of 8 total)
Author Posts
December 21, 2013 at 3:17 am 13847
Rogier Hello, I have added a category text field to my post submission form. When a user starts typing the category appears in drop down below. I can then select the category. I also have a tags text field that does a similar thing (drop down only appears if the tag has been used before). What's strange is that the post category doesn't get assigned but the post tags do! My settings for the category are: Type: Text Input Order by: Name Order: ASC Selection Type: Include I'm not sure what to put in the selection terms but I've tried both with the categeory IDs and without! Why is the category not being attached to the post? I have the post going to pending review and when I confirm the post then it get assigned to the default category and not the category selected in the text input in the form submission. Help please! I have purchased this and it's just not doing what it should.
December 21, 2013 at 5:08 am 13852
Mahi Mahi

You sure you used right post type and right category/Taxonomies field?

December 21, 2013 at 5:13 am 13855
Andrew Andrew

Hello Mahi,

Yes, I’m using Post Type: Post and yes the category section which when saved turns to Taxonomy. The categories appear when I start typing and I can select one, it just doesn’t appear when I submit it.

However, it works when I select a tag which is the weird thing. I can provide you access if you could have a look? Will obviously reply privately.

Thanks,
Andy

December 21, 2013 at 2:42 pm 13866
Tareq Hasan Tareq Hasan

Hey Andy, categories will not work this way I guess. You need to provide category ID’s to update the categories as the category taxonomy is hierarchical. Tags aren’t hierarchical and works with text input, so it works.

December 21, 2013 at 2:51 pm 13867
Andrew Andrew

Is there no way then this will work with inputting text? It finds the categories fine and separates them with a comma. Is there not a tweak with the code we could do? I need to be able to write multiple categories in.

December 23, 2013 at 2:06 pm 13899
Andrew Andrew

Any idea how this can be done? Surely, if the categories are appearing, it’s possible to get the ID of that category. Really need this feature.

Your help would be appreciated.

Thanks,
Andy

December 24, 2013 at 12:27 am 13911
Tareq Hasan Tareq Hasan

Sorry for replying late.

I was tinkering with this, try this code. Paste this to your functions.php
[php]
function wpufe_set_post_category( $post_id ) {
if ( isset( $_POST[‘category’] ) ) {
$categories = $_POST[‘category’];

$hierarchical = array_map( ‘trim’, array_map( ‘strip_tags’, explode( ‘,’, $categories ) ) );
wp_set_object_terms( $post_id, $hierarchical, ‘category’ );
}

}

add_action( ‘wpuf_add_post_after_insert’, ‘wpufe_set_post_category’ );
add_action( ‘wpuf_edit_post_after_update’, ‘wpufe_set_post_category’ );
[/php]

December 24, 2013 at 2:50 pm 13926
Andrew Andrew

Hi Tareq,

That is brilliant! Works perfectly 🙂 Thank you so much for your help, much appreciated!

Hope you have a great Christmas & a happy new year!

Thanks again,
Andy

March 3, 2014 at 8:21 pm 16110
Rogier Rogier

Hi Team,

How does it work if I want to have it work with the Product Categories from WooCommerce? I have tried, but it only takes my child category and doesn’t automatically add the parent category.

I have tried the following:

function wpufe_set_post_category( $post_id ) {
if ( isset( $_POST[‘product_cat’] ) ) {
$categories = $_POST[‘product_cat’];

$hierarchical = array_map( ‘trim’, array_map( ‘strip_tags’, explode( ‘,’, $categories ) ) );
wp_set_object_terms( $post_id, $hierarchical, ‘product_cat’ );
}

}

add_action( ‘wpuf_add_post_after_insert’, ‘wpufe_set_post_category’ );
add_action( ‘wpuf_edit_post_after_update’, ‘wpufe_set_post_category’ );

But as said this doesn’t work.

Thanks in advanced for the support.

Best regards,

Rogier

Viewing 8 Posts - 1 through 8 (of 8 total)