Get ACF Field Values from an Options Page

Retrieve field values stored on an ACF options page from anywhere in your theme or plugin.

php options
|

Retrieve field values stored on an ACF options page from anywhere in your theme or plugin.

Pass 'option' as the second parameter to get_field():

<?php
$phone   = get_field( 'company_phone', 'option' );
$email   = get_field( 'company_email', 'option' );
$address = get_field( 'company_address', 'option' );

if ( $phone ) {
    echo '<a href="tel:' . esc_attr( $phone ) . '">' . esc_html( $phone ) . '</a>';
}

Output a field directly in a template:

<?php the_field( 'footer_text', 'option' ); ?>

Loop through a repeater on an options page:

<?php if ( have_rows( 'social_links', 'option' ) ) : ?>
    <ul class="social-links">
        <?php while ( have_rows( 'social_links', 'option' ) ) : the_row(); ?>
            <li>
                <a href="<?php echo esc_url( get_sub_field( 'url' ) ); ?>">
                    <?php the_sub_field( 'platform' ); ?>
                </a>
            </li>
        <?php endwhile; ?>
    </ul>
<?php endif; ?>

If you registered your options page with a custom post_id, use that instead of 'option':

<?php
// Registration with custom post_id.
acf_add_options_page( [
    'page_title' => 'Theme Settings',
    'menu_slug'  => 'theme-settings',
    'post_id'    => 'theme_settings',
] );

// Retrieval using the custom post_id.
$logo = get_field( 'logo', 'theme_settings' );

Stay Updated

Get ACF tips and new extensions in your inbox

No spam. Unsubscribe anytime.