Post Not Assigning to Category
Author | Posts |
---|---|
December 21, 2013 at 3:17 am 13847 | |
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 | |
You sure you used right post type and right category/Taxonomies field? | |
December 21, 2013 at 5:13 am 13855 | |
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, | |
December 21, 2013 at 2:42 pm 13866 | |
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 | |
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 | |
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, | |
December 24, 2013 at 12:27 am 13911 | |
Sorry for replying late. I was tinkering with this, try this code. Paste this to your $hierarchical = array_map( ‘trim’, array_map( ‘strip_tags’, explode( ‘,’, $categories ) ) ); } add_action( ‘wpuf_add_post_after_insert’, ‘wpufe_set_post_category’ ); | |
December 24, 2013 at 2:50 pm 13926 | |
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, | |
March 3, 2014 at 8:21 pm 16110 | |
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 ) { $hierarchical = array_map( ‘trim’, array_map( ‘strip_tags’, explode( ‘,’, $categories ) ) ); } add_action( ‘wpuf_add_post_after_insert’, ‘wpufe_set_post_category’ ); But as said this doesn’t work. Thanks in advanced for the support. Best regards, Rogier |