Dropdown Post

The dropdown-post lets you add a select field with list of posts.

Dropdown Post

Parameters

Here are the parameters in adding dropdown-post.

id
string | required

a unique slug-like string to use as an id and also as index in saving data in database.

label
string | optional

the label of the field.

description
string | optional

the description of the field and display under the label.

section
string | requiredl

the section where the field will be displayed.

default
integer | optional

the default value of the field.

Note: default value must be a post id.

priority
integer | optional

determines the order of fields in section.

order
string | optional

sets the order to ascending and descending.

Note: order only accept 'asc' and 'desc'.

Example


Yano::field( 'dropdown-post', [
   'id'          => 'dropdownpostdb1',	
   'label'       => 'Select Post',
   'description' => 'You can select a page in here.',
   'section'     => 'section_id',
   'priority'    => 1,
   'order'       => 'asc'
] );

Example with default value! note: default value must existing post id.


Yano::field( 'dropdown-post', [
   'id'          => 'dropdownpostdb1',	
   'label'       => 'Select Post',
   'description' => 'You can select a post in here.',
   'section'     => 'section_id',
   'default'     => 100,
   'priority'    => 1,
   'order'       => 'desc'
] );

Usage

The get_theme_mod() function is recommended to retrieve data.


// Get the post by id
$post = get_post( get_theme_mod('dropdownpostdb1') );