• On this page you will see I’m listing events that fall in certain months: https://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?

  • The topic ‘WordPress giving a 404 page when passing a year argument different than the curr’ is closed to new replies.