Question on Multiple Categories and Sub Categories

This topic contains 3 reply and 3 voices, and was last updated by Joe F 9 years, 10 months ago
Viewing 3 Posts - 1 through 3 (of 3 total)
Author Posts
June 10, 2014 at 8:54 am 21681
Joe F Hello, Just purchased the plugin and I'm very happy with it thus far. I have a few questions... 1) I'm trying to allow my users to post to multiple categories within my taxonomy in my custom post type. I researched my question and found the following code which works for forcing the post to be included into one category or the categories that I list in the code... function wpufe_set_default_cat( $post_id, $form_id ) { if ( 347 == $form_id ) { // change the number to your form ID wp_set_post_terms( $post_id, array( 38 ), 'category' ); // the number is category ID } if ( 372 == $form_id ) { // change the number to your form ID wp_set_post_terms( $post_id, array( 39 ), 'category' ); // the number is category ID } } add_action( 'wpuf_add_post_after_insert', 'wpufe_set_default_cat', 10, 2 ); However, I'd like my users to have the option to post to multiple categories within the form, which I added to my form successfully but when the above code is included in the functions.php, it overrides my user form submissions for this specific taxonomy. Is there a way to force the post to post within a taxonomy custom post type category, but also have other options within that taxonomy included in my form for users to choose without one getting overwritten? Basically, my taxonomy is called review_categories and my post type is reviews. I want the post to force inclusion in the review_categories subcategory called "loglines," which is when I used the above code in the functions.php. I also want the users to have a choice on the form between other subcategories within review_categories like subcategory "length" which allows the user to choose "feature, novel, pilot," and another subcategory within review_categories called "completion" and have the user choose between "new, old." When I include the subcategory options in my form for the user to choose AND include the code in the functions.php, the code within the functions.php overrides my users choices which I don't want. So is there a way to enable both of them? Thanks and sorry for the long explanation but hope it's clear. Joe
June 18, 2014 at 12:41 am 22079
Mark Mark

I am having this problem as well. The taxonomies display ok on the front end form however when I save the item the taxonomies do not save. Other fields save ok, just not the custom taxonomy fields. The taxonomies are created using CPT-onomies: Using Custom Post Types as Taxonomies

June 18, 2014 at 1:36 pm 22114
Sk Sk
function wpufe_set_default_cat( $post_id, $form_id ) {

    if ( 347 == $form_id ) { // change the number to your form ID
        wp_set_post_terms( $post_id, array( 38 ), ‘category’ ); // the number is category ID
    }

    if ( 372 == $form_id ) { // change the number to your form ID
        wp_set_post_terms( $post_id, array( 39 ), ‘category’ ); // the number is category ID
    }
}

add_action( ‘wpuf_add_post_after_insert’, ‘wpufe_set_default_cat’, 10, 2 );

You need to change form ID and category ID according to your form id and category id.

please if you have done this.

Thank you.

June 19, 2014 at 12:30 am 22157
Joe F Joe F

Thanks for the code. I get this but I also need the user to choose a category separate from the categories I want to force the form post to be included in. When I use a post field allowing the user to choose a category, the forced commands in the code override the users choice of category. I need the form to be included in all three categories…the two forced categories using code and the users choice of category in the form field. Is this possible? Thanks!

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