Home › Forums › Backend Issues (wp-admin) › Can't get value from options page in functions.php › Reply To: Can't get value from options page in functions.php
Hi there @krtmedia
Initially you will want to create the Options Page. You can use this code resource, or this plugin.
Here’s example code for an Options Page that can be added to functions.php or a custom plugin:
<?php
if( function_exists('acf_add_options_page') ) {
$option_page = acf_add_options_page(array(
'page_title' => 'Global Settings',
'menu_title' => 'Global Settings',
'menu_slug' => 'my-global-settings',
'capability' => 'edit_posts',
'redirect' => false
));
}
?>
Then, you create a Fieldset within ACF for that Options page.
So… you create a URL field called “pricelist” for example.
Then… you visit the Options Page and give your “pricelist” field a value, and click “Update”.
Then… to reference it with code..
<?php
// to 'echo' it
the_field('pricelist', 'option');
// to return the value, and perhaps assign it to a variable for later use
$price_list = get_field('pricelist', 'option');
?>
Is that helpful, or do you need further assistance?
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
CPT registration is coming to ACF! We demoed the new feature during the most recent session of ACF Chat Fridays. Check out the summary for the details. https://t.co/k2KQ3WWBAz
— Advanced Custom Fields (@wp_acf) March 7, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.