Utilities
Yano also provide useful methods that will help your task.
Gets an array of pages
The Yano_Util::_get_pages()
returns all the pages in an array.
$pages = Yano_Util::_get_pages(); // this will return the page id and page title
/**
* Using in field
*
* In this example we will going to use this in select field in choices
*/
Yano::field( 'select', [
'id' => 'selectdb1',
'label' => 'Select Page',
'section' => 'section_id',
'priority' => 1,
'choices' => Yano_Util::_get_pages()
] );
Gets an array of posts
The Yano_Util::_get_posts()
returns all the posts in an array.
$posts = Yano_Util::_get_posts(); // this will return the post id and post title
/**
* Using in field
*
* In this example we will going to use this in select field in choices
*/
Yano::field( 'select', [
'id' => 'selectdb1',
'label' => 'Select Posts',
'section' => 'section_id',
'priority' => 1,
'choices' => Yano_Util::_get_posts()
] );
Gets an array of custom post type
The Yano_Util::_get_post( $post_type )
returns all the post in specific post type in an array, it has 1 parameter $post_type
.
/**
* Lets assume that we have a custom post "project"
*/
$projects = Yano_Util::_get_post( 'project' ); // this will return the post id and post title in post "project"
/**
* Using in field
*
* In this example we will going to use this in select field in choices
*/
Yano::field( 'select', [
'id' => 'selectdb1',
'label' => 'Select Projects',
'section' => 'section_id',
'priority' => 1,
'choices' => Yano_Util::_get_post( 'project' )
] );
Gets all available taxonomy
The Yano_Util::_get_taxonomies()
returns taxonomy slug and name.
$taxonomies = Yano_Util::_get_taxonomies(); // this will return the taxonomy slug and name
/**
* Using in field
*
* In this example we will going to use this in select field in choices
*/
Yano::field( 'select', [
'id' => 'selectdb1',
'label' => 'Select Taxonomy',
'section' => 'section_id',
'priority' => 1,
'choices' => Yano_Util::_get_taxonomies()
] );
Gets all available post types
The Yano_Util::_get_post_types()
returns post type slug and name.
$post_types = Yano_Util::_get_post_types(); // this will return post type slug and name
/**
* Using in field
*
* In this example we will going to use this in select field in choices
*/
Yano::field( 'select', [
'id' => 'selectdb1',
'label' => 'Select Post Type',
'section' => 'section_id',
'priority' => 1,
'choices' => Yano_Util::_get_post_types()
] );
Gets material colors
The Yano_Util::_get_material_colors( $type )
returns a set of material colors. It has 1 parameter $type
and here are the valid types all
, primary
, a100
, a200
, a400
, a700
, red
, pink
, purple
, deepPurple
, indigo
, lightBlue
, cyan
, teal
, green
, lightGreen
, lime
, yellow
, amber
, orange
, deepOrange
, brown
, grey
, blueGrey
.
/**
* In this example we will going to use in color set field
*/
// Example 1: return all material color
Yano::field( 'color-set', [
'id' => 'colorsetdb1',
'label' => 'Choose Color 1',
'description' => 'Some description',
'section' => 'sectisection_idon_1',
'default' => '#000000',
'priority' => 14,
'colors' => Yano_Util::_get_material_colors( 'all' ), // returns all the material color
'shape' => 'square',
'size' => 20
] );
// Example 2: return primary color only
Yano::field( 'color-set', [
'id' => 'colorsetdb1',
'label' => 'Choose Color 1',
'description' => 'Some description',
'section' => 'sectisection_idon_1',
'default' => '#000000',
'priority' => 14,
'colors' => Yano_Util::_get_material_colors( 'primary' ), // returns all the primary color
'shape' => 'square',
'size' => 20
] );
// Example 3: return purple color only
Yano::field( 'color-set', [
'id' => 'colorsetdb1',
'label' => 'Choose Color 1',
'description' => 'Some description',
'section' => 'sectisection_idon_1',
'default' => '#000000',
'priority' => 14,
'colors' => Yano_Util::_get_material_colors( 'purple' ), // returns all the purple color
'shape' => 'square',
'size' => 20
] );