Skip Navigation

[Resolved] populate drop-down list with custom field type single-line text

This support ticket is created 6 years, 5 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
- 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)

Tagged: 

This topic contains 4 replies, has 2 voices.

Last updated by davidm-13 6 years, 5 months ago.

Assisted by: Luo Yang.

Author
Posts
#921144

Tell us what you are trying to do?
I need a function to populate a drop-down list from custom field type - single-line text.
I have several drop-down lists all populated from custom field type single-line text. So I just want to pass the slug (of the custom field) to the function according to which drop-down I want to populate.
Appreciate any code snippets.

Thanks
David

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?

#921166

Hello,

There isn't exact same feature within Toolset, but as a workaound you can produce the dropdown menu with Views custom search form, for example, you can try these:
1) Create a post view, querying the posts or custom post type
2) Add search form in above view, with the custom field filter, setup the field as "select" type, see our document:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-control-postmeta

type (opt):
'checkbox' | 'checkboxes' | 'date' | 'datepicker' | 'radios' | 'select' | 'textfield' | 'multi-select'

#921315

Hi Luo, thanks for your reply.
Truth is I have the following function, could you tell me how to convert it from listing a taxonomy field to listing a custom field (type single line text):

/**
* Plugin Name: Select plant by taxonomy tag term
* Description: Create select dropdown list of taxonomy terms, select term to open plant details page. 
*              Select box uses jQuery Chosen plugin. 
* Version: 1.0 
* Author: David Myers
*/

function select_post_by_tax_tag($atts) {
    extract(shortcode_atts(array(
          'list_name' => 1, ), $atts));
    $args = array(
        'orderby'       => 'name',
        'order'         => 'ASC',
        'hide_empty'    => 1,
        'taxonomy'      => $list_name, //change this to any taxonomy
    );
        $select_box = '';
    foreach (get_categories($args) as $tax) :
        $args = array(
            'post_type'         => 'plant', //change to your post_type
            'posts_per_page'    => 1,
            'orderby'           => 'title',
            'order'             => 'ASC',
            'tax_query' => array(
                array(
                    'taxonomy'  => $list_name, //change this to any taxonomy
                    'field'     => 'slug',
                    'terms'     => $tax->slug
                )
            )
        );
        if (get_posts($args)) :

        foreach(get_posts($args) as $p) : 
		if (strlen($tax->name) > 2) 
          $select_box.='<option value="' . get_permalink($p) . '">' . $tax->name . '</option><br/>';
        endforeach;
        endif;
    endforeach; 
	return $select_box;
}
 
add_shortcode('post_by_eng_name', 'select_post_by_tax_tag');


?>

Thanks
David

#921499

As I mentioned above, there isn't exact same feature within Toolset, according to our support policy, we don't provide custom codes support:
https://toolset.com/toolset-support-policy/

You might consider to check it with our experienced contractors:
https://toolset.com/contractors/

#921641

Hi Luo,
Thanks, I'll give the toolset view a go. One question - is the view for the whole page or can I just insert the view shortcode for the dropdown select list, and leave the rest of the page as is?

Thanks
David