Home Forums Plugin Support WP User Frontend Pro Default Category for Submission

This topic is: resolved

This topic contains 8 replies, has 4 voices, and was last updated by  Tareq Hasan 5 years ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #1992

    VVV
    Participant
    Post count: 9

    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

    #1993

    Tareq Hasan
    Keymaster
    Post count: 2831

    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.

    #1994

    VVV
    Participant
    Post count: 9

    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?

    #2001

    Tareq Hasan
    Keymaster
    Post count: 2831

    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]

    #2002

    VVV
    Participant
    Post count: 9

    Thanks again Tareq

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

    Many thanks again.

    Rich

    #9606

    Marie-Hélène
    Participant
    Post count: 15

    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

    #9612

    VVV
    Participant
    Post count: 9

    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

    #19243

    Dana
    Member
    Post count: 15

    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

    #19285

    Tareq Hasan
    Keymaster
    Post count: 2831

    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 9 posts - 1 through 9 (of 9 total)

The topic ‘Default Category for Submission’ is closed to new replies.