Skip Navigation

[Resolved] Using urlparam in CRED shortcode to pre select the taxonomies field in CRED form

This support ticket is created 6 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 4 replies, has 2 voices.

Last updated by Nigel 6 years, 2 months ago.

Assisted by: Nigel.

Author
Posts
#1101508

Hi,

This is the continuation from this ticket :
https://toolset.com/forums/topic/using-taxonomies-views-to-select-custom-taxonomies-in-toolset-forms-cred/

sorry for my late response, I was caught with other works and forget to test this out

I already create the views and create the loop output with this :
hidden link;">[wpv-taxonomy-title]

In the front end it already working fine, it return the url link with the taxonomy slug.
And in Cred I also have the shortcode for this taxonomy field like this :
[cred_field field='merek-mesin' display='checkboxes' urlparam='merek-mesin' output='bootstrap']

But in the front-end form I don't have any taxonomy field already pre selected at all
Is it something that I miss in the shortcode?

Fyi, the custom taxonomy slug that I am using is called "merek-mesin"

#1101640

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi there

Sorry, I think I must have got my wires crossed when I replied to your earlier thread, mixing preselecting a custom field value vs preselecting a taxonomy value.

Pre-selecting a taxonomy value is not possible.

The value or urlparam attributes of the cred_field shortcode only work for custom fields, not for taxonomies.

That is an unfortunate limitation, and we have a feature request to make those attributes work the same for taxonomies as for custom fields.

The only option is to not include the taxonomy field in your form and to instead set it using the Forms API when the form is submitted, using cred_save_data, for example: https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

Sorry for the confusion, I need to go back and edit that prior ticket because my response is incorrect.

#1102479

Hi Nigel,

Thanks for your response, so the only way is to add it using Forms API, do you mind to provide me the code for this one, because I am not very familiar with php code in the link you give me

#1102548

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Sure. I'm out of time today, but I'll look at it on Monday.

#1104505

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Here you go.

You need to edit the taxonomy, the default term, and the form ID:

function tssupp_set_default_term( $post_id, $form_data ){

	$default_tax = 'status';
	$default_term = 'submitted'; // slug

	if ( in_array( $form_data['id'], array( 7 ) ) ) { // Edit form ID (or IDs)

		$term = get_term_by( 'slug', $default_term, $default_tax );

		wp_set_post_terms( $post_id, $term->term_id, $default_tax );

	} 

}
add_action( 'cred_save_data', 'tssupp_set_default_term', 10, 2 );