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 6889047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:06:24+00:00 2026-05-27T06:06:24+00:00

this is some basic IF THEN statement stuff but I’m a coding newbie so

  • 0

this is some basic IF THEN statement stuff but I’m a coding newbie so I’m hoping someone can throw me a bone :-).

I have several posts that have a custom date field. I want to:

1) loop through all those posts and evaluate whether the date fields from everyone of the posts are in the past. If so, I want to display the special message.

2) If just one of the posts is in the past I want to keep evaluating until the end of all posts in the query are reached.

3) If even one post with a date that is in the future is found I have some more content to display from that post instead of the special message.

Currently, the special message is only showing up when the item in the loop has no post content at all. I was also able to get it to return the message after each post was evaluated but then I got a special message for each post evaluated, and I just want to get one message even at any point any one of the posts returns true.

My current code is this:

                        <?php

                        $parent = get_cat_name($category[0]->category_parent);
                        $cur_cat = $cur_cat_slug; 
                        $cur_date = current_time('timestamp',0);

                        echo $cur_cat_name;

                        ?>
                    </div>

                    <div class=dates>
                        <?php

                        $categoryvariable=$category; // assign the variable as current category
                        $query= 'cat=' . $cur_cat_id. '&posts_per_page=100&meta_key=date_value&orderby=meta_value&order=ASC&meta_compare=>=&meta_value=$cur_date'; // concatenate the query
                        query_posts($query); // run the query
                        if ( have_posts() ) : while ( have_posts() ) : the_post();
                        $date_value = get_post_meta($post->ID, 'date_value', true);
                        if ($date_value>=$cur_date)
                            {
                        ?> 
                            <a class=dates-link href="<?php the_permalink(); ?>">
                            <li><?php echo date("D, n/j/Y, g:ia", get_post_meta($post->ID, 'date_value', true)); ?> - <?php $key="course_endtime"; echo get_post_meta($post->ID, $key, true); ?>
                            </a>
                        <div class=info>
                            <table cellpadding=0 cellspacing=3 border=0>
                                <tr>
                                    <td valign=top><img src="<?php bloginfo('template_directory'); ?>/images/i.jpg"></td>
                                    <td>Click any date for more info about a course and to register online.</td>
                                </tr>
                            </table>
                        </div>
                        <?php
                            } 

                        endwhile; else:

                        ?>

                        <div class=course-content>Sorry, no courses are currently scheduled. See <a href="http://dynamictactical.org/courses/" style="color:#000000; text-decoration:underline;">Course Calendar</a> for all upcoming DTT courses.</div>
                        <? endif;
                        wp_reset_query();?>
  • 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-05-27T06:06:24+00:00Added an answer on May 27, 2026 at 6:06 am

    Here’s my little bone:
    Use a boolean flag to determine whether or not you need to display the special message, and display the message only after the loop.
    Do something like this:

     Set $specialmessage = true;
    

    before the loop.
    Then, inside the loop, when you find a post more recent than the date you’re testing against, set it to false and stick the_content in a holder. You can use break to exit the loop if you want.Then,

    if($specialmessage)
         echo 'special message'
    else
         echo the_content_placeholder.
    

    Not a coding expert, but my best advice.

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

Sidebar

Related Questions

I have some basic idea on how to do this task, but I'm not
This might look like a basic question to some of you but I expect
This is a really basic question but... I have some code like this var
This should be a very basic design question, but for some reason it doesn't
I know this sounds confusing: I have just built some basic prev/next pagination for
This is a fairly basic question, which for some reason, a proper solution escapes
This might be basic question, however I am confused on some .Net Concpets. I
I got this doubt while writing some code. Is 'bool' a basic datatype defined
I'm stuck with this. I'm self studying assenbler and translating some basics instructions. But
I have already seen a post about the error but This is some what

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.