Home Forums Plugin Support WP User Frontend (Free Version) Auto-assign custom taxonomy?

This topic is: resolved

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

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #5444

    jman057
    Participant
    Post count: 16

    Hi Tareq,

    I plan to have different groups of users creating posts with wpuf, and would like to be able to organise posts by groups. I can create a new form for each group and use the custom field _wpuf_form_id to query/filter posts, however it would be great if I could set all posts created by a form to a custom taxonomy. Is there a way to achieve this? Perhaps a hidden field with default value? Understand if this request is beyond normal support as it's not a current feature.

    Loving the plugin, will write up a testimonial once the site is up and happy to give you the site URL.

    Cheers,

    Jamie

    #5468

    Tareq Hasan
    Keymaster
    Post count: 2831

    May be you should check this reply. If it was a category taxonomy, the post settings has this option already. As you are trying with custom taxonomy, applying the action hook is the solution right now.

    #5569

    jman057
    Participant
    Post count: 16

    Thanks Tareq, worked perfectly!

    #5631

    jman057
    Participant
    Post count: 16

    Hi Tareq,

    Thanks again, Although I have realised that it would be better if I could auto assign a tax based on the user (so I'm not creating a new forms for each user) so I tried the following but it doesn't work (works when I substitute $user_id for $form_id)

    function wpufe_set_default_cat( $post_id, $user_id ) {
      
        if ( 3 == $user_id ) { // change the number to your user ID
            wp_set_post_terms( $post_id, array( 49 ), 'ctax_instution' );  // the number is category ID
        }
    
        if ( 2 == $form_id ) { // change the number to your form ID
            wp_set_post_terms( $post_id, array( 39 ), 'ctax_instution' ); // the number is category ID
        }
    }
      
    add_action( 'wpuf_add_post_after_insert', 'wpufe_set_default_cat', 10, 2 );

    Again, realise this is beyond the normal level of support, so understand if you don't reply, but if it's a quick fix then any advice would be appreciated. Thanks!

    #5634

    Tareq Hasan
    Keymaster
    Post count: 2831

    The second parameter in the function is $form_id, not $user_id. You can get the current users id by this: $user_id = get_current_user_id();. Now you can compare and set the taxonomy.

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Auto-assign custom taxonomy?’ is closed to new replies.