Default Category for Submission

This topic contains 8 reply and 4 voices, and was last updated by Tareq Hasan 9 years, 11 months ago
Viewing 8 Posts - 1 through 8 (of 8 total)
Author Posts
April 10, 2013 at 3:06 pm 1992
Tareq Hasan I am after the same functionality that the free version offered. I do not want users to see any category selection on the front end while posting. all posts are going to one category, so any kind of option on the front end is superfluous as creates a bad UI. Please help. Thanks Rich
April 10, 2013 at 3:26 pm 1993
Tareq Hasan Tareq Hasan

The removal behind the default category is: you might have a post type that doesn’t support “category” taxonomy. So it becomes pointless.

Although, you can set the default category by adding some code.
[php]
function wpufe_set_default_cat( $post_id, $form_id ) {
$expected_form_id = 12;
$default_cat = 13; // put the category ID

if ( $expected_form_id == $form_id ) {
wp_set_post_terms( $post_id, array( $default_cat ), ‘category’ );
}
}

add_action( ‘wpuf_add_post_after_insert’, ‘wpufe_set_default_cat’, 10, 2 );
[/php]

Put the code to your themes functions.php and provide your forms id to $expected_form_id and your default category ID to $default_cat. That should work.

April 10, 2013 at 3:34 pm 1994
VVV VVV

Hi Tareq.

Thank you for your response.

I appreciate what you are saying, but must disagree.

It is not pointless, the option may become redundant if the post type does not support category.
But what if it does?

I have 2 different forms, each to post to 2 separate categories. In this instance, the option would have been very handy.

Would it not make sense to have the option there if required?! What would the work around be?

April 10, 2013 at 5:11 pm 2001
Tareq Hasan Tareq Hasan

I also understand your concern. You are seeing it from a user perspective and I am seeing it from my developer perspective. There might be a settings in a next release for default “category” taxonomy.

But for your workaround right now, I only can give you that code snippet. Change the category ID and form ID as you need.
[php]
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 );
[/php]

April 10, 2013 at 5:24 pm 2002
VVV VVV

Thanks again Tareq

I will implement the code and get back if there are any issues.

Many thanks again.

Rich

October 30, 2013 at 8:10 pm 9606
Marie-Hélène Marie-Hélène

Hi Tareq!
I’ve tried both of these code in my function.php.. but I’m steal not able to give a specific category to my post form.
Can you help me please 🙂
Thx

October 30, 2013 at 11:14 pm 9612
VVV VVV

Hi Marie-Hélène.
The latest version of the plugin has this feature included.
If you go to the ‘Post Settings’ tab of the form in question, you will see “Default Post Category”.

Best wishes
Rich

April 22, 2014 at 9:02 pm 19243
Dana Dana

I am a new user and I am also having trouble with this. I need all front end submitted posts to go to a “User Submitted” category along with the category chosen in the actual form..

So each user submitted post will automatically show up in two different categories?

I have my default category chosen as “user submitted” and a category for them to choose in the actual form, but it only shows up in the one they choose and not the default “user submitted” category..

Any way to work around this? Thanks

April 23, 2014 at 5:02 pm 19285
Tareq Hasan Tareq Hasan

The both will not work at once. It’ll pick the category if it exists in the form, otherwise the default category will be used.

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