Auto-assign custom taxonomy?

This topic contains 4 reply and 2 voices, and was last updated by Tareq Hasan 11 years, 4 months ago
Viewing 4 Posts - 1 through 4 (of 4 total)
Author Posts
July 1, 2013 at 8:43 am 5444
Tareq Hasan 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
July 1, 2013 at 4:05 pm 5468
Tareq Hasan Tareq Hasan

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.

July 4, 2013 at 8:04 am 5569
jman057 jman057

Thanks Tareq, worked perfectly!

July 6, 2013 at 1:58 pm 5631
jman057 jman057

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!

July 6, 2013 at 5:22 pm 5634
Tareq Hasan Tareq Hasan

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 4 Posts - 1 through 4 (of 4 total)