Skip to content

Instantly share code, notes, and snippets.

@ashwebstudio
Created May 7, 2013 20:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashwebstudio/5535744 to your computer and use it in GitHub Desktop.
Save ashwebstudio/5535744 to your computer and use it in GitHub Desktop.
<?php
class acf_field_divisions extends acf_field
{
// vars
var $settings, // will hold info such as dir / path
$defaults; // will hold default field options
/*
* __construct
*
* Set name / label needed for actions / filters
*
* @since 3.6
* @date 23/01/13
*/
function __construct()
{
// vars
$this->name = 'divisions';
$this->label = __('Divisions');
$this->category = __("Choice",'acf'); // Basic, Content, Choice, etc
$this->defaults = array(
// add default here to merge into your field.
// This makes life easy when creating the field options as you don't need to use any if( isset('') ) logic. eg:
//'preview_size' => 'thumbnail'
);
// do not delete!
parent::__construct();
// settings
$this->settings = array(
'path' => apply_filters('acf/helpers/get_path', __FILE__),
'dir' => apply_filters('acf/helpers/get_dir', __FILE__),
'version' => '1.0.0'
);
}
/*
* create_field()
*
* Create the HTML interface for your field
*
* @param $field - an array holding all the field's data
*
* @type action
* @since 3.6
* @date 23/01/13
*/
function create_field( $field )
{
global $wpdb;
?>
<div>
<select name="fields[<?php echo $field['key']; ?>]">
<option value="">Select Division</option>
<?php
$qry = "SELECT * FROM divisions ORDER BY id DESC";
$divisions = $wpdb->get_results( $qry );
foreach ($divisions as $division) {
echo '<option value="'.$division->id.'" '.selected($field['value'],$division->id,0).'>'.$division->name.'</option>';
}
?>
</select>
</div>
<?php
}
}
// create field
new acf_field_divisions();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment