Skip Navigation

[Resolved] $title in hook wpt_field_options not working with TERM FIELD

This thread is resolved. Here is a description of the problem and solution.

Problem: I am using the wpt_field_options hook to modify the options in a custom term select field, but the $title parameter is always empty.

Solution: The wpt_field_options hook is no longer supported. The best way to manage these options is to use wp-admin.

This support ticket is created 6 years, 7 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Tagged: 

This topic contains 6 replies, has 2 voices.

Last updated by Christian Cox 6 years, 7 months ago.

Assisted by: Christian Cox.

Author
Posts
#692620
ts002.JPG
ts001.JPG
ts000.JPG

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;
  }
#694255

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.

#710363

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.

#711715

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.

#711926

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.

#713663

Is there ANOTHER way how to create via your API dynamically options in SELECT?

#718070

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.