Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
2  
do you have movie posts where you've set the publish date to 1994? see this answer. –  Milo Aug 17 at 15:54

2 Answers

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' );
share|improve this answer

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?

share|improve this answer
 
No I don't have. How do you setup this ? By the way WP always selects 404.php template in my case ... –  Alex Aug 17 at 7:49
 
Another question for that here and it seems well answered. wordpress.stackexchange.com/questions/61896/… –  WebTechGlobal Aug 17 at 11:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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