Home Forums Backend Issues (wp-admin) Can't get value from options page in functions.php


Can't get value from options page in functions.php

  • I need to get a file url for a metabox i created in my functions.php. The field “pricelist” is t field of type “file” and returns the url.

    function add_pricelist_metaboxes() {
    	add_meta_box('digiart_pricelist', 'Preisliste Produktion', 'digiart_pricelist', 'produktionsauftrag', 'side', 'low');
    function pricelist() {
    	global $post; 
        <p><?php the_field('pricelist', 'option'); ?></p>
    add_action( 'add_meta_boxes', 'add_pricelist_metaboxes' );<code></code>
  • 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:

    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..

    // 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?

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Can't get value from options page in functions.php’ is closed to new replies.