Skip Navigation

[Resolved] fill dropdown filter dynamically

This support ticket is created 6 years, 1 month 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/Hong_Kong (GMT+08:00)

This topic contains 1 reply, has 2 voices.

Last updated by Luo Yang 6 years, 1 month ago.

Assisted by: Luo Yang.

Author
Posts
#1141354

Tell us what you are trying to do?
I need to fill the dropdown for filter search with extra information, like post title and the post ID, etc.

Is there any documentation that you are following?
I try this hook but seen to not work with last version of toolset. Many posts using this code is from 2017.

**
* Dynamically populate 'Country' custom field
* Using 'country' custom post type
*/
add_filter( 'wpt_field_options', 'custom_country_field_options', 10, 3);
function custom_country_field_options( $options, $title, $type ){
echo "string";
die();

if ( 'Country' == $title ) {

$options = array( // Initial empty state option
array(
'#value' => '',
'#title' => '-- Select Country --'
)
);

// Get country posts
$args = array(
'post_type' => 'oferta',
'post_status' => 'published'
);
$country_posts = get_posts( $args );

foreach ($country_posts as $country){
// Update custom field options with countries
$options[] = array(
'#value' => $country->ID,
'#title' => $country->post_title
);
}
}
return $options;
}

Is there a similar example that we can see?

What is the link to your site?

#1141976

Hi,

The filter hook "wpt_field_options" is working in the latest version of Toolset Views + Types plugin, but it works only for the custom select/radio field created by Types plugin.

According to your codes, I suggest you try with a custom select field "Country", and a post type "oferta", then debug your codes line by line, manually.

Since it is a custom PHP codes problem, if you still need assistance for it, please provide a test site with the same problem, also point out the problem page URL + view URL, and where I can edit your PHP codes, I need a live website to test and debug.