Skip Navigation

[Resolved] Setting the category for forms that add posts.

This support ticket is created 5 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 7 replies, has 2 voices.

Last updated by MarkJames 5 years, 2 months ago.

Assisted by: Minesh.

Author
Posts
#1378033

I have two forms

Add new artwork (ID: 27215) and Add new written work (ID: 27221) - when the user completes them the status is set to pending review.

I want the new artwork form to be set to the category artworks and the other written work.

I have created the function below but it doesn't seemt to set the categories.

add_action('cred_save_data', 'add_review_terms_automatically',10,2);
function add_review_terms_automatically($post_id, $form_data) {
$forms = array( 27215, 27221 );
$post_terms = array();
if ( in_array( $form_data['id'], $forms ) )
{
if($form_data['id'] == 27215){
$post_terms = array('artwork');
}

if($form_data['id'] == 27221) {
$post_terms = array('written-work');
}

wp_set_object_terms($post_id, $post_terms, 'review-category', false);
}
}

Cab you see what the issue is.

Many thanks

Mark

#1378039

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

There looks some coding mistake in your hook.

Can you please try to use the following code and try to resolve your issue:

add_action('cred_save_data', 'add_review_terms_automatically',10,2);
function add_review_terms_automatically($post_id, $form_data) {
 
$post_terms = array();
 if($form_data['id'] == 27215){
	$post_terms = array('artwork');
}

if($form_data['id'] == 27221) {
	$post_terms = array('written-work');
}

wp_set_object_terms($post_id, $post_terms, 'review-category', false);

}

Please make sure that term slug and taxonomy slug you are using is correct.

#1378067

Unfortunately it didn't work.

I have checked the form ids and the slugs and the are correct.

Do you have any other ideas?

Many thanks

Mark

#1378565

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I need access details to check what's going wrong with your install. Please share the problem URL where you added the form and access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#1379575

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Unfortunately, the access details you shared is not working at this end.

When I try to login to wp-admin, it says:

"The password you entered for the email address mark.james@scip.org.uk is incorrect."

Can you please send me working access details.

I have set the next reply to private which means only you and I have access to it.

#1380557

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I checked on your install and I found that you are using the wrong taxonomy slug. I see taxonomy you are using is the default category: hidden link

I've changed the following line of code:

wp_set_object_terms($post_id, $post_terms, 'review-category', false);

To

wp_set_object_terms($post_id, $post_terms, 'category', false);

Then I've added two dummy entry "toolset test 1" for artwork form and "toolset test 2" for written work form and I see its terms are associated correctly. Can you please confirm it works at your end as well.

#1380809

Thank you for your help with this - I can see where I have made a mistake.

Hopefully it will help other people too.

#1380811

My issue is resolved now. Thank you!