0

On this page you will see I'm listing events that fall in certain months: http://conciergemaps.ch/events/

This is on Wordpress, When you select a certain month and year it appends the URL with two arguments (month and year i.e. ?month=October&year=2014). The problem is if the year is anything other than the current year (2014), it gives a 404 error. I use the below code to only show the correct events that fall under the selected month (they're a custom post type):

$events_month = sanitize_text_field($_GET["month"]);
$events_year = sanitize_text_field($_GET["year"]);

if (empty($events_month) || empty($events_year)) {

    $events_month = date('F');
    $events_year = date('Y');

}

$ts = strtotime("$events_month $events_year");

$month_start_date = date('Ym01', $ts);
$month_end_date = date('Ymt', $ts);

$args = array(
    'post_type' => 'events',
    'posts_per_page' => 50,
    'order' => 'ASC',
    'orderby' => 'meta_value_num',
    'meta_key' => 'start_date',
    'meta_query' => array(
        array(
            'key' => 'start_date',
            'value' => $month_end_date,
            'type' => 'numeric',
            'compare' => '<='
        ),
        array(
            'key' => 'finish_date',
            'value' => $month_start_date,
            'type' => 'numeric',
            'compare' => '>='
        )
    ),
);

$events = new WP_Query($args);

Why is this causing a 404 when the year is anything other than the current year? If there are no events that fall in the current month it should just say "there are no events to show" which is handled in a further query, but this just switches the page to the 404 page

1

Ok the problem was with using 'year' as the argument name, if I changed it to something else such as 'y' it seems to work.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.