# Using the data Argument

The data argument allows Redux to populate the field using dynamic queries for posts, pages, menus, categories, terms, etc. It automatically uses WordPress APIs to retrieve each type of data. Most data types accept an 'args' value, which is passed to the WordPress function to control the retrieved data.

# Built-in Values

Data Key Description
categories Gets data using the WordPress get_categories() (opens new window) function.
menus Gets data using the WordPress function wp_get_nav_menus() (opens new window).
pages Gets data using the WordPress function get_pages() (opens new window). See Using 'pages' for additional details.
terms Gets data using the WordPress function get_terms() (opens new window). See Using 'terms' for additional details.
taxonomies Gets data using the WordPress function get_taxonomies() (opens new window).
posts Gets data using the WordPress function get_posts() (opens new window).
post_types Gets data using the WordPress function get_post_types() (opens new window).
tags Gets data using the WordPress function get_tags() (opens new window).
image_sizes Gets data from the $_wp_registered_nav_menus global array. Does not support additional arguments
menu_locations Gets data from the $_wp_additional_image_sizes global array. Does not support additional arguments
elusive-icons Gets a list of all the Elusive Icons.
roles Gets all the $wp_roles global array. Does not support additional arguments
sidebars Gets all the registered sidebars from $wp_registered_sidebars global array. Does not support additional arguments
capabilities Gets all the roles in the $wp_roles global array. Does not support additional arguments
callback Gets data by calling the function defined in args as a string. See Using 'callback' for additional details.
users Gets data using the get_users() (opens new window) function.

# Examples and Usage

# Standard Select Using Posts

$fields = array(
    'id'    => 'opt-select-post',
    'type'  => 'select',
    'title' => esc_html__( 'Select Post', 'your-textdomain-here' ), 
    'data'  => 'posts',
    'args'  => array(
        'post_type'      => 'post_type_name',
        'posts_per_page' => -1,
        'orderby'        => 'title',
        'order'          => 'ASC',
    )
);

# Button Set Using Terms

    $fields = array(
        'id'    => 'opt-button-set-term',
        'type'  => 'select',
        'title' => esc_html__( 'Select Term', 'your-textdomain-here' ), 
        'data'  => 'terms',
        'args'  => array(
            'taxonomies' => array( 'taxonomy_name' ),
            'hide_empty' => false,
        )
    );

# Example Usage

This example is based on the example usage provided above. Be sure to change $redux_demo to the value you specified in your opt_name argument.

global $redux_demo;

echo 'Selected post: ' . $redux_demo['opt-select-post'];
echo 'Selected term: ' . $redux_demo['opt-button-set-term'];

# Using terms

array(
    'data' => 'terms',
    'args' => array(
        'taxonomies' => array( 'taxonomy_name' ),
    )
)

# Using pages

The default results for the pages value returns only 20 items. If you wish to increase this limit, you can use the example below. If you set the value to -1 you'll get everything in the database. Warning, this can be quite detrimental to a website if there are a large number of posts.

array(
    'data' => 'pages',
    'args' => array(
        'posts_per_page' => 30,
    ),
)

# Using a Custom callback

Sometimes you may need to fetch data in a different way than Redux has set up. In that case, you can use a custom callback function.

array(
    'data' => 'callback',
    'args' => 'my_callback_function'
)

TIP

The callback function should return an array. The keys will be saved, and the values displayed.

function my_callback_function() {
	return array(
		'here' => 'Here I am',
		'rocking' => 'Rocking like a hurricane',
	);
}