3

I'm using gravity form to create some custom post type - as events.

Everything is working great, There is some date field to setup the event from x to y date. ALl of this working great.

However, I have a function that hides all the events from the passers - which works fine as well. The problem I'm having is that it doesn't display the event of the D-DAY !

Example: Some events have been posted from 01/06 until 09/06. ON the 09/06 the event doesn't display, it should . . .

Any help will be incredible, I'm really having headache with that !

Thanks !

Below is that function:

function custom_posts_where( $where, $query ) {
    if (is_singular()) return $where;

    if (($query->query_vars['post_type'] == 'events' || (is_array($query->query_vars['post_type']) && $query->query_vars['post_type'][0] == 'events'))) {
        $year = 0;
        $month = 0;
        if (preg_match('@/([0-9]{4})/([0-9]{1,2})/@', $_SERVER['HTTP_REFERER'], $refer_match)) {
            $year = $refer_match[1];
            $month = $refer_match[2];

        }
        else if (preg_match('@/([0-9]{4})//@', $_SERVER['HTTP_REFERER'], $refer_match)) {
            $year = $refer_match[1];
        }

        if (is_archive()) {
            if (!is_month() && !is_year()) {
                $where .= " AND wp_postmeta.meta_value >= now()";
            }
            else {
                $where = preg_replace("@AND.*?\) \)@i", '', $where);
                if (is_month() || is_year()) {
                    $where .= " AND YEAR(wp_postmeta.meta_value) = " . $query->query_vars['year'];
                }
                if (is_month()) {
                    $where .= " AND MONTH(wp_postmeta.meta_value) = " . $query->query_vars['monthnum'];
                }
            }
        }
        else if ($year > 0 || $month > 0) {
            if ($year) {
                $where .= " AND YEAR(wp_postmeta.meta_value) = " . $year;
            }
            if ($month) {
                $where .= " AND MONTH(wp_postmeta.meta_value) = " . $month;
            }
        }
        else {
            if (!is_search || is_home() ) {
                $where .= " AND wp_postmeta.meta_value >= now()";
            }

        }
    }
    return $where;

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.