Using WordPress ‘get_alloptions()’ PHP function

The get_alloptions() WordPress PHP function retrieves all autoload options, or all options if no autoloaded ones exist.

Usage

$options = get_alloptions();

Parameters

  • This function has no parameters.

More information

See WordPress Developer Resources: get_alloptions()

Examples

Display All Options

Retrieve all options and display them in a list.

$options = get_alloptions();
echo '<ul>';
foreach ($options as $key => $value) {
    echo '<li><strong>' . $key . '</strong>: ' . $value . '</li>';
}
echo '</ul>';

Check If Option Exists

Check if a specific option exists.

$options = get_alloptions();

if (array_key_exists('option_name', $options)) {
    echo 'Option exists!';
} else {
    echo 'Option does not exist.';
}

Get Option Value

Retrieve the value of a specific option.

$options = get_alloptions();
$option_value = $options['option_name'];
echo 'The value of the option is: ' . $option_value;

Get Option Count

Count the number of options.

$options = get_alloptions();
$count = count($options);
echo 'There are ' . $count . ' options.';

Filter Options by Prefix

Retrieve options with a specific prefix.

$options = get_alloptions();
$prefix = 'my_prefix_';
$filtered_options = array_filter($options, function ($key) use ($prefix) {
    return strpos($key, $prefix) === 0;
}, ARRAY_FILTER_USE_KEY);

foreach ($filtered_options as $key => $value) {
    echo '<strong>' . $key . '</strong>: ' . $value . '<br>';
}