Dropdown Custom Post

The Dropdown Custom Post controller allows users to select a post from a certain post type using a dropdown menu.

Demonstration

 
Handy::control( 'dropdown-custom-post', [
    'id'          => 'dropdown_custom_post_id',
    'section'     => 'layout_section',
    'label'       => esc_html__( 'Dropdown Custom Post Control', 'textdomain' ),
    'description' => esc_html__( 'Description Here', 'textdomain' ),
    'priority'    => 1,
    'post_type'   => 'products'
]);

TIP

Here's an example using the default parameter. Note the default value accepts only a valid post id from defined post_type.

 
Handy::control( 'dropdown-custom-post', [
    'id'          => 'dropdown_custom_post_id',
    'section'     => 'layout_section',
    'default'     => 100,
    'label'       => esc_html__( 'Dropdown Custom Post Control', 'textdomain' ),
    'description' => esc_html__( 'Description Here', 'textdomain' ),
    'priority'    => 1,
    'post_type'   => 'products'
]);

TIP

Here's an example using the post_type, status and order parameters. Note the post_type value accepts only the name of a custom post type, while status values accepts only publish, future, draft, pending, private, trash, auto-draft and inherit, for further details, read WordPress Post Status. And the order value only accepts asc (assending) and desc (decending) order.

 
Handy::control( 'dropdown-custom-post', [
    'id'          => 'dropdown_custom_post_id',
    'section'     => 'layout_section',
    'default'     => 100,
    'label'       => esc_html__( 'Dropdown Custom Post Control', 'textdomain' ),
    'description' => esc_html__( 'Description Here', 'textdomain' ),
    'priority'    => 1,
    'post_type'   => 'products',
    'status'      => [ 'publish', 'pending' ],
    'order'       => 'asc'
]);

Basic Usage

 
// Return an integer.
$value = get_theme_mod( 'dropdown_custom_post_id' );

Parameters

NameDescription
id

string required

The unique slug like string used as an ID and also as an index name in storing data in a database.

section

string required

The ID of the section in which the control will be displayed.

default

integer optional

The predetermined value of the control. Accepts only a valid post id from defined post_type. Default empty.

post_type

string required

The name of a custom post type that will used it's post as dropdown options.

status

array optional

The status of a post. Accepts only publish, future, draft, pending, private, trash, auto-draft and inherit, for further details, read WordPress Post Status. Default empty array.

order

string optional

The order of the posts. Accepts only asc (assending) and desc (decending) order. Default desc.

label

string optional

The label or title of the control to show in the UI. Default empty.

description

string optional

The description of the control to show in the UI. Default empty.

priority

integer optional

The order of control appears in the section. Default 0.

validations

array optional

The set of validations used to validate the value of the control. For further details, read validations. Default empty.

active_callback

callable optional

A callback function that determines the visibility of a control, whether to show or hide depending on a condition. For further details, read active_callback. Default empty.

sanitize_callback

callable optional

A callback function that sanitizes the value of control before storing it in the database. Note that this is only optional since each control is already well sanitized. For further details, read sanitize_callback. Default empty.