$14
Retrieving values with "get_option();"
I created a custom options panel within my admin area for my wordpress theme. (I followed the tutorial in this link)
Everything is working just fine.
When I try to retrieve a value within a page template using get_option, everything works as expected.
An example of the code used to pull a value is:
get_option('ss_latesttweet');The issue I'm having is that I am trying to retrieve a value using the same technique, but within a file that is not a page template. The file is a separate PHP file that is located in the themes main directory.
I'm assuming that I need to somehow add connection information, or pass some sort of values to this PHP file so that it is able to execute the built in wordpress function of: get_option();
Any help is greatly appreciated.
WP Answers | 04/13/10 at 5:17pm
| Edit
(3) Possible Answers Submitted...
-

Last edited:
04/13/10
5:34pmMilan Petrovic says:get_option is a function registered by WordPress, and you need to load WordPress to use it. Easiest way is to include wordpress load file on top of your php file:
<?php require_once("path/to/wp-load.php"); ?>
Be aware that this will load almost entire WordPress engine (nothing visual, but all functions and classes).Previous versions of this answer: 04/13/10 at 5:25pm
- 04/13/10 5:34pm
WP Answers says:Works like a charm.
Thank you very much Milan.
- 04/13/10 5:34pm
-

Last edited:
04/13/10
5:29pmJarret Minkler says:Don't use a file, simply use add_option("myhack_extraction_length", '255', '', 'yes');
As from this page http://codex.wordpress.org/Function_Reference/add_option
If you must get from file, open the file
$fh = fopen('filename', 'r');
and loop through the lines adding each using the add_option function
while($line = fgets($fh)){
add_option(...);
}
This will create a new option in the database. then you can use get_option and update_option normally.Previous versions of this answer: 04/13/10 at 5:29pm | 04/13/10 at 5:29pm
-

Last edited:
04/13/10
5:41pmBuzu B says:If you don't want to load up the entire wp engine, you can always perform a regular query to the data base. I can explain more on that if you want. Just let me know.
- 04/13/10 7:08pm
WP Answers says:Hi Buzu,
Is there any kind of security threat or anything for loading up the entire engine?
Would it be more beneficial to just perform a query to the database?
Thanks a lot for your input.
- 04/13/10 7:08pm
This question has expired.
Current status of this question: Completed





