WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have created a custom image uploader for my wordpress admin panel and need to retrieve the data from the wp_options table. I have wrritne the below function:

//function to get all slider images
function getSliderImages(){
global $wpdb, $theme_shortname;
$query = "SELECT * FROM $wpdb->options AS o1 
WHERE o1.option_name LIKE '%".$theme_shortname."_header_image%'";
$imgs = $wpdb->get_results($query);

$images = array();
//loop through images and remove unusable results
foreach($imgs as $i){
    $id = substr($i['option_name'],0,-1);
        $images[] = $i['option_value'];


How do I access the returned array in header.php on the front end? this function is currently in themes/themename/functions.php

share|improve this question
up vote 0 down vote accepted

In your header.php

$images = getSliderImages();
    foreach ( $images as $img ) {
        echo '<img src="' .$img. '" />';
share|improve this answer
This was the way i tried it first but I get this error from the function. Fatal error: Cannot use object of type stdClass as array in /Users/wadem/Sites/gpsite/wp-content/themes/PracticeInABox/functions.php on line 747 The line it refers to is $id = substr($i['option_name'],0,-1); – mattwadey May 10 '12 at 11:13
Try $id = substr( $->option_name, 0,1 ); – Chris_O May 10 '12 at 11:18
That's it sorted thanks v much – mattwadey May 10 '12 at 11:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.