Forums

Using the WP get_option() function (4 posts)

  1. holliday22
    Member
    Posted 1 year ago #

    So how do you use WordPress's variable get_option() function to set a variable?

    I tried:

    $variable=get_option('option');

    But I had no luck. Got an error message as "Call to undefined function."

    I tried including /wp-includes/functions.php but it made no difference.

    Anyone got any idea? Thanks!

  2. holliday22
    Member
    Posted 1 year ago #

    I figured it out. I wasn't including /wp-includes/functions.php in the file where the function was located.

    When I figured that out, I got another error: Fatal error: Call to a member function main() on a non-object

    It took me 2 hours to figure that one out. The problem was something like this:

    I was including functions.php in example.php and then including example.php in options_menu.php. So in options_menu.php, the include statement was in the body section of the page which cause the error.

    Long story short, include the functions file within the necessary function rather than at the file level!

  3. GRAQ
    Member
    Posted 1 year ago #

    Usually (for theme development) your functions are put in functions.php - that is what it is there for.

  4. holliday22
    Member
    Posted 1 year ago #

    I'm working on a plugin, FWIW.

Topic Closed

This topic has been closed to new replies.

About this Topic