Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7978971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:38:13+00:00 2026-06-04T09:38:13+00:00

I am having some problems to make the following code to work in my

  • 0

I am having some problems to make the following code to work in my side bar of wordpress:

            $the_query = get_posts( $args );


            $year_post = 0;
            foreach ($the_query as $post) : 
                setup_postdata($post);
                $current_year = get_the_time('Y'); 
                if( $current_year != $year_post ) {
                    $year_post = $current_year;
                    echo '<li><a href="'.get_year_link($current_year).'">'.$current_year.'</a></li>';
                }
                $month_post = 0;
                foreach ($post as $post_monthly) : 
                       setup_postdata($post_monthly);  
                       $current_month = get_the_time('m');
                        if ($current_month != $month_post){
                               $month_post =$current_month;
                               echo '<li><a href="'.get_year_link($current_month).'">'.$current_month.'</a></li>';
                        }

                        foreach ($post_monthly as $post_title) : 
                                setup_postdata($post_title);

                                echo '<li><a href="'.get_permalink().'">'.the_title().'</a></li>';
                        endforeach;

                endforeach;

            endforeach;

            wp_reset_postdata();


With this code I am trying to display the following:

  • 2012
    -May

    • Lorem ipsum
    • Lorem ipsum
    • Lorem ipsum

It display 2012, May, but when it comes to display the titles of the post I am getting the following error: “Warning: Invalid argument supplied for foreach() ”

I have checked so many times this code, I just don’t seem to see the problem.

Can anyone see something that I am missing, It will be highly appreciated.
Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T09:38:15+00:00Added an answer on June 4, 2026 at 9:38 am

    The return value of get_posts() is an array of objects. So then, your $post contains an object, not an array.
    http://codex.wordpress.org/Template_Tags/get_posts

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some problems with the following code: with open('townhall.map', 'r') as f: for
Having some problems with a solution that apparently works: <script type=text/javascript > //following code
I'm having some problems with the following code: private class ClientPluginLoader : MarshalByRefObject {
Im having some problems getting the Sticky Footer to work on my site. If
I'm having some trouble understanding why this code won't work. I got it from
I have been having some trouble getting the following to work: <IfModule mod_rewrite.c> DirectoryIndex
So I am having some real difficulty figuring out how to make the following
Currently having some problems- now = datetime.datetime.now() month = now.strftime(%B) site = wikipedia.getSite('en', 'wikiquote')
Im having some problems with a simple toggle in Safari. A really annoying flickering
I have been having some problems with mp4 video on Android . The codec

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.