0

I have a custom type on my wordpress site called 'movie'.

If the user type this URL : http://mysite.com/1994,
I would like to display all movies published in 1994.

Unfortunately, I get a consistent 404 error. When I call get_post_type in index.php(that is the template page called since I didn't defined 404.php), it displays 'movie' but I have no movie called 1994... at least not yet.

I have pretty permalinks ON.

If I ask the rewrite rule inspector to check the URL, here is the result for http://mysite.com/1994:

([0-9]{4})/?$   index.php?year=$matches[1]  date
(.?.+?)(/[0-9]+)?/?$    index.php?pagename=$matches[1]&page=$matches[2] page
([^/]+)(/[0-9]+)?/?$    index.php?name=$matches[1]&page=$matches[2] post

What am I missing?

1
  • 2
    do you have movie posts where you've set the publish date to 1994? see this answer.
    – Milo
    Aug 17, 2013 at 15:54

2 Answers 2

1

Here is the solution of my problem, thanks to @Milo:

function wpa_date_archive_post_types( $query ){
    if( $query->is_main_query() && $query->is_date() ):
        $query->set( 'post_type'   , array( 'movie'   ) );
        $query->set( 'year'        , 0                );
        $query->set( 'tag'         , '1994' );
        $query->set( 'post_status' , array( 'publish' ) );
    endif;
}
add_action( 'pre_get_posts', 'wpa_date_archive_post_types' );
0

Displaying multiple posts by 1994 makes "1994" a term in a taxonomy, much like Categories or Tags are taxonomy.

So you need to think about a template suitable for taxonomy, listing multiple posts. You'll need another template for viewing any movie clicked on.

Do you have a taxonomy setup for Dates Alex?

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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