Title: wp_get_archives doesn&#039;t work as array
Last modified: August 19, 2016

---

# wp_get_archives doesn't work as array

 *  [Bijan641](https://wordpress.org/support/users/bijan641/)
 * (@bijan641)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/wp_get_archives-doesnt-work-as-array/)
 * wp_get_archives works unless I try to output it to an array. If I do that I get
   this error:
 * Warning: Invalid argument supplied for foreach() in /home/dotswoof/public_html/
   beta/wp-content/themes/swoof/archive.php on line 92
 * Here is the link:
    [http://www.dotswoof.com/beta/?page_id=68](http://www.dotswoof.com/beta/?page_id=68)
 * Here is the code:
 *     ```
       $args = array(
                           'type'            => 'postbypost',
                           'format'          => 'link',
                           'show_post_count' => false,
                           'echo'            => 0 );
   
                           $archive = wp_get_archives($args);
   
                           foreach ($archive as $post)
                           {
                               echo $post->post_name;
                           }
       ```
   
 * I don’t know why this isn’t working and I’m on a deadline. Any help would be 
   greatly appreciated.

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Thread Starter [Bijan641](https://wordpress.org/support/users/bijan641/)
 * (@bijan641)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/wp_get_archives-doesnt-work-as-array/#post-1916185)
 * Wow this got pushed to page 5 in a matter of hours. Sorry, but I need to bump
   this!
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/wp_get_archives-doesnt-work-as-array/#post-1916188)
 * [wp_get_archives](http://codex.wordpress.org/Function_Reference/wp_get_archives)
   does not return an array so it can’t be used in a foreach loop
 *  Thread Starter [Bijan641](https://wordpress.org/support/users/bijan641/)
 * (@bijan641)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/wp_get_archives-doesnt-work-as-array/#post-1916200)
 * This is would it says on the codex page:
 * > echo
   >  (boolean) Display the output or return it. 1 (True) – Default 0 (False)
 * I assume return it must mean an array. What else could it mean? And if this is
   not the case, is there any other way to complete control the format of the output?
 * For example, I can’t seem to find a way to post the date and the name in list
   format.
 *  [Curtiss Grymala](https://wordpress.org/support/users/cgrymala/)
 * (@cgrymala)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/wp_get_archives-doesnt-work-as-array/#post-1916203)
 * Unfortunately, you’re assuming incorrectly. `wp_get_archives()` can either echo
   the HTML code for the archive list, or it can return that HTML code as a variable.
   It does not return an array. It builds the HTML and either displays it or returns
   it.
 * If you want to tweak the output, you’re either going to have to do some sort 
   of search and replace on the returned HTML, or you’re going to have to build 
   your own function to retrieve the archive list as an array.
 *  Thread Starter [Bijan641](https://wordpress.org/support/users/bijan641/)
 * (@bijan641)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/wp_get_archives-doesnt-work-as-array/#post-1916216)
 * Thank you! That is very helpful.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘wp_get_archives doesn't work as array’ is closed to new replies.

## Tags

 * [array](https://wordpress.org/support/topic-tag/array/)
 * [foreach](https://wordpress.org/support/topic-tag/foreach/)
 * [wp_get_archives](https://wordpress.org/support/topic-tag/wp_get_archives/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 3 participants
 * Last reply from: [Bijan641](https://wordpress.org/support/users/bijan641/)
 * Last activity: [15 years, 3 months ago](https://wordpress.org/support/topic/wp_get_archives-doesnt-work-as-array/#post-1916216)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
