I am trying to:
Create dynamic select with wpt_field_options, but the second parameter with name $title is empty when I call it on
/wp-admin/term.php?taxonomy=destination&tag_ID=4&post_type=person
My code {It is copy paste from yours https://toolset.com/forums/topic/populate-select-field-with-list-of-posts-in-a-custom-post-type/}
/**
* TOOLSET TYPES Create Custom SELECT With Pages
*/
add_filter('wpt_field_options', 'populate_select', 10, 3);
function populate_select($options, $title, $type)
{
// Variable $title is empty everytime on /wp-admin/edit-tags.php and works well only on /wp-admin/post.php
switch ($title)
{
case 'Pages':
$options = array();
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => '_wp_page_template',
'value' => 'template-program.php',
'compare' => '=',
),
),
);
$posts_array = get_posts($args);
foreach ($posts_array as $post)
{
$options[] = array(
'#value' => $post->ID,
'#title' => $post->post_title,
);
}
break;
}
return $options;
}
Hi, I see what you're describing and I can replicate this on my local site. The wpt_field_options filter is not officially documented, so I need to reach out to my 2nd tier team to see if this is expected behavior and the filter is not intended for term meta fields, or if this is a bug. I'll update you when I have some more information to share.
I got some additional feedback on this from my 2nd tier team. At the current time, this filter is undocumented and is not officially supported. We have found that changing the options using this wpt_field_options filter can cause unexpected problems in custom search Views, so we no longer recommend using it. The best way to manage these options is via wp-admin and the field editor interface.
Use admin UI is not solution for me. I am programmer and I need API, which can solve the issue. Personally I do not use your VIEWS plugin. If you know a way, how to at least temporarily fix it, please let me know.
I found one solution for this moment:
/**
* TOOLSET TYPES Create Custom SELECT With Pages
*/
add_filter('wpt_field_options', 'populate_select', 10, 3);
function populate_select($options, $title, $type)
{
// ungly hack based on fake option created in admin UI which can me unique per select
if (!empty($options[1]['#title']) && $options[1]['#title'] == 'Page Select Not Working!')
{
if ($posts_array = getDestinationHomepages())
{
$options = array(0 => $options[0]);
foreach ($posts_array as $post)
{
$options[] = array('#value' => $post->ID,
'#title' => $post->post_title,);
}
}
}
return $options;
}
Anyway - It would be more nice when wpt_field_options will support $slug instead of $title, or object with whole input field params.
Anyway - It would be more nice when wpt_field_options will support $slug instead of $title, or object with whole input field params.
This is not going to happen, sorry. This filter is no longer supported.
Is there ANOTHER way how to create via your API dynamically options in SELECT?
No, I would definitely provide an alternative if one existed. I cannot offer one here, the old method is not supported and there is no documented way to do this in the current system.