Thank you for sharing these details.
You can register a custom shortcode to check the existence of a specific custom field value from a field with multiple values.
For example:
add_shortcode('check_custom_field_value', 'check_custom_field_value_func');
function check_custom_field_value_func( $atts ) {
$a = shortcode_atts( array(
'field' => '',
'value' => ''
), $atts );
$value = '0';
$field_values = types_render_field( $a['field'], array( "separator" => "##" ) );
if(!empty($field_values)) {
$field_values_arr = explode('##', $field_values);
if(in_array($a['value'], $field_values_arr)) {
$value = '1';
}
}
return $value;
}
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 add "check_custom_field_value" in the "Third-party shortcode arguments" section, at WP Admin -> Toolset -> Settings -> Front-end Content.
This custom shortcode can accept two parameters:
- field: slug of the field to check the target value from
- value: the target value/text to check
For example, to check if the value 'two' exists from the field with slug 'book-single-lines', the shortcode can be used, as:
[check_custom_field_value field='book-single-lines' value='two']
The shortcode will return '0' if the target value is not found and '1' if it is found.
The same shortcode can be used in a conditional statement as:
[wpv-conditional if="( '[check_custom_field_value field='book-single-lines' value='two']' eq '1' )"]
The target option exists!
[/wpv-conditional]
Note: The custom code examples from our forum are shared to get you started in the right direction. You're welcome to adjust them as needed and for more personalized customization assistance, you can consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/