Skip to content
This repository has been archived by the owner on May 31, 2021. It is now read-only.

Field helper: Select

sy4mil edited this page Jan 28, 2013 · 4 revisions

Description

Return HTML select, with appropriate class, type, name, id and values.

Usage

aq_field_select($field_id, $block_id, $options, $selected);

Parameters

$field_id
(string)(required) The field id e.g. 'categories'

$block_id
(string)(required) The id of the block. You can get this from the $instance variable of the block.

$options
(array)(required) Associative array of options

$selected
(string)(required) The selected value saved by the block, extracted from $instance

Return

Return HTML select string, with appropriate values selected

Example

<?php 

$my_options = array (
   'one' => 'My Pony',
   'two' => 'His Pony'
);

echo aq_field_select('categories', $block_id, $my_options, $categories);

 ?>

This will display a select input. When the user selected e.g. My Pony, then the block will save the "key" value i.e. one. Remember that when you're using this value on the front end.

Notes

Changelog

Since 1.0

Clone this wiki locally