Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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);
    if(is_numeric($id)){
        $images[] = $i['option_value'];
    }
}

return($images);
}

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

1 Answer 1

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

 
discard

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.