Skip Navigation

[Resolved] Continuation of closed ticket – Setting up a new view.

This support ticket is created 2 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

This topic contains 4 replies, has 2 voices.

Last updated by katinaA 2 years, 2 months ago.

Assisted by: Waqar.

Author
Posts
#2469153

I'm sorry I let this go for so long that the ticket was closed. I had a bunch of other work I had to complete and then we had a hurricane come through here and I'm now able to resume working.

I'm continuing the ticket from here:

https://toolset.com/forums/topic/setting-up-a-new-view/

I see that you have 2022 now displaying titles mostly properly. There is one problem remaining. Our field has two options - 2021 Award Winner and 2022 Aware Winner. The values and code you worked on are now working for displaying Partners that are 2021 or 2022 Award Winners correctly. But it is not working correctly for Partners that are BOTH 2021 AND 2022 Award Winners. We made that field a checkbox and not a radio button because we have Partners that will have both years selected. We'll be adding all future years to these options and Partners will always be able to be Award Winners in multiple years. We need the 2021 Awards Winners page and the 2022 Award Winners page to show all partners that won in those years.

I saw the three test partners that you created titled Toolset Test 1 - 2021, Toolset Test 1 - 2022, and Toolset Test 2 - 2022. I changed the last one of these to Toolset Test 2 - 2021 and 2022 and selected both checkboxes. That page appears properly on the 2021 Award Winners page, but it does not appear on the 2022 Award Winners page.

This is the part that is confusing for me. I saw where you said once it sees 2021, it doesn't check for 2022. So I'm guessing that is the issue. We need it to check for both 2021 AND 2022 and display any of them that have both selected on both pages. Once I see how you code this conditional once, I'll then be able to update it as needed when we add 2023 Award Winners as an option. But right now, I'm not understanding how to check it this way.

Thanks for any further assistance you can provide.

#2470017

Hi,

Thank you for contacting us and I'd be happy to assist.

To implement a conditional check for multiple options in the checkboxes type field, it would be better to register a custom shortcode:


add_shortcode( 'custom_field_contains_check', 'custom_field_contains_check_func');
function custom_field_contains_check_func($atts) {
	$field = $atts['field'];
	$value = $atts['value'];

	$result = '0';

	if(!empty($field) && !empty($value)) {
		$field_content = types_render_field( $field, array( "separator" => ",", "output" => "raw" ) );
		if(!empty($field_content)) {
			$field_content_arr = explode(',', $field_content);
			if( in_array( $value, $field_content_arr ) ) {
				$result = '1';
			}
		}
	}

	return $result;
}

The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.

Next, please also add "custom_field_contains_check" in the "Third-party shortcode arguments" section, at WP Admin -> Toolset -> Settings -> Front-end Content.

This shortcode accepts two parameters:
field: slug of the custom field to check the value from
value: value to check if it exists or not

The shortcode will return '0' if the value doesn't exist and '1' if the value exists.

And then you can use this shortcode in your conditional checks, like this:

To check for the value '2020', for the field "partner-awards"


[wpv-conditional if="( '[custom_field_contains_check field='partner-awards' value='2020']' eq '1' )"]
[wpv-post-title]<br>
[/wpv-conditional]

To check for the value '2021', for the field "partner-awards":


[wpv-conditional if="( '[custom_field_contains_check field='partner-awards' value='2021']' eq '1' )"]
[wpv-post-title]<br>
[/wpv-conditional]

And so on, for the other year value options, that you'll add in the future.

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#2471163

I've applied everything you said and *I think* it is working. But I'm not 100% on that yet. Give me a bit before marking this one as resolved. I have to compare the full results on the 2021 and 2022 pages to lists I have of what *should* be displaying there. I should be able to get this done later today.

#2471881

Thanks for the update and sure, please take your time.

You're welcome to mark this ticket as resolved, once confirmed.

#2473563

My issue is resolved now. Thank you!