Using WordPress ‘get_autotoggle()’ PHP function

The get_autotoggle() WordPress PHP function retrieves the auto_toggle setting for a specified category.









  • $id (int) – The category ID to get the auto_toggle setting for. If no category supplied, it uses 0.

More information

See WordPress Developer Resources: get_autotoggle


Get auto_toggle for a specific category

Retrieve the auto_toggle setting for category ID 3.

$cat_id = 3;
$toggle_setting = get_autotoggle($cat_id);

Check if auto_toggle is enabled for a category

Determine if auto_toggle is enabled for category ID 7.

$cat_id = 7;
$toggle_setting = get_autotoggle($cat_id);
$is_enabled = $toggle_setting == 1 ? true : false;

Display auto_toggle setting for all categories

Loop through all categories and display the auto_toggle setting for each.

$categories = get_categories();
foreach ($categories as $category) {
    $toggle_setting = get_autotoggle($category->term_id);
    echo "Category ID {$category->term_id}: Auto Toggle - {$toggle_setting}";

Enable or disable auto_toggle based on the setting

Enable or disable a feature based on the auto_toggle setting for category ID 10.

$cat_id = 10;
$toggle_setting = get_autotoggle($cat_id);

if ($toggle_setting == 1) {
    // Enable the feature
} else {
    // Disable the feature

Update auto_toggle setting for a category

Update the auto_toggle setting for category ID 15 to the opposite of its current setting.

$cat_id = 15;
$toggle_setting = get_autotoggle($cat_id);
$new_setting = $toggle_setting == 1 ? 0 : 1;

update_option("category_toggle_{$cat_id}", $new_setting);

Tagged in

Leave a Comment

Your email address will not be published. Required fields are marked *