Skip Navigation

[Resolved] wpt_field_options filter

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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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 16 replies, has 2 voices.

Last updated by svenA-3 1 year ago.

Assisted by: Minesh.

Author
Posts
#2660367

Sure, but the original idea was, to populate that dropdown dynamically, so with each new year a new entry.
Am I to conclude this is not possible with search filter dropdowns?

Regards,

Sven

#2660721

OK, I have a solution for my needs. Modified your suggestion as follows:

[wpv-filter-start]
[wpv-filter-controls]
<div class="form-group">
<label for="wpv-wpcf-berichtsjahr">[wpml-string context="wpv-views"]Berichtsjahr[/wpml-string]</label>
[wpv-control-postmeta field="wpcf-berichtsjahr" type="select" source="custom" url_param="filter-year" values="[annrep_year option='values']" display_values="[annrep_year option='labels']" ]
</div>
[/wpv-filter-controls]
[wpv-filter-end]

shortcode annrep_year registered with Toolset Views settings.

Script for shortcode annrep_year:

function generate_year_list( $atts ) {
// Get current year
$current_year = date('Y');

// Start year
$start_year = 2022;

// Parse the attributes
$attributes = shortcode_atts( array(
'output' => 'labels',
), $atts );

// Initialize the output string
$output = '';

// Generate the year list
for ( $year = $start_year; $year <= $current_year; $year++ ) {
// For 'labels', include "Please Select," at the beginning
if ( $attributes['output'] === 'labels' && $year == $start_year ) {
$output .= "Please Select,";
}

// Append the year to the output
$output .= $year;

// If not the last year, append a comma
if ( $year < $current_year ) {
$output .= ',';
}
}

// For 'values', prepend a comma at the beginning
if ( $attributes['output'] === 'values' ) {
$output = ',' . $output;
}

return $output;
}

// Add the shortcode to WordPress
add_shortcode( 'annrep_year', 'generate_year_list' );