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?
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'
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
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/
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