Custom Field Template
Get today's date and compare to value in date picker (6 posts)

  1. Ericka125
    Posted 4 years ago #

    I am currently using Custom Field Template. I need to make everything as simple as possible for the client, and so to make an event I've created a custom field with the date picker tool displaying the date as mm/dd/yyyy (the preferred format; if possible would like to keep this).

    Going into the backend, I'm trying to code the php for get today's date and the query meta comparison. Here is the code I have:

    <?php  //Get today's date in the right format
    $todaysDate = date('m/d/Y');
    <?php query_posts('showposts=-1&category_name=Event&meta_key=StartDate&meta_compare=>=&meta_value=' . $todaysDate . '&orderby=meta_value&order=ASC'); ?>

    This is not currently working and I can't figure out what I'm doing wrong. Just to reemphasize, I am only trying to post events that have not yet occurred, hence why I need to make the comparison.

    If I've made anything unclear let me know and I will clarify as soon as possible. And thank you in advance for any feedback.


  2. zstoy
    Posted 4 years ago #

    I'm having the exact same issue. The funny thing is that upcoming events are showing only for events this year. As soon as I post an event next year they are not showing.

    It must be something in the call of the $todayDate... Do you think we can call that in a different format?
    Anyone else have any ideas?

  3. Ericka125
    Posted 4 years ago #

    Still needing help with this. Anyone have any thoughts on how to fix this?

  4. michaellawrence
    Posted 3 years ago #

    im having the same problem with the year issue. 2013 dates aren't showing

  5. michaellawrence
    Posted 3 years ago #

    using $todaysDate

  6. Pelligea
    Posted 3 years ago #

    Not sure if this is able to help anyone or not. But I had a similar issue. I swapped out the code and made the format come back as separate values. So through custom fields I saved year, month and day as different values. Then I compared it to each.

    $Month = get_post_meta($post->ID, 'Month', true);
    $Day = get_post_meta($post->ID, 'Day', true);
    $Year = get_post_meta($post->ID, 'Year', true);
    $today = getdate();
    if (($today[year] < $Year ) ||
            (($today[year] == $Year) &&
    	($today[mon] < $Month)) ||
    	(($today[year] == $Year) &&
    	($today[mon] == $Month) &&
    	($today[mday] <= $Day))) {

    I know I may not have done it the best way. But with my poor knowledge of php or coding in general this worked.

    This allowed me to not only use the code for upcoming events, but also made easy to later apply it as a recent events formula.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Custom Field Template
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic