In short, I'm moved some articles from default post-type to custom post type. And now, my articles are accessible using an old www.example.com/articleurl/
and a new one www.example.com/blog/articleurl/
urls.
There is a problem: a client added an article with url '2093'. And it's accessible using www.example.com/blog/2093/
. But when I try to get it using www.example.com/2093/
wordpress tries to get some archive of 2093 year or category(there is no such category, by the way) and then redirects to the index page.
So how to solve this?
No, I can't change url of this article. I need to leave it 2093
.
Yes, I need this hierarchy of my site and I need custom post type.
Create a file called archive-2093.php in your theme root and add the following code:
<?php
$args = array (
'name' => '2093',
'post_type' => array( 'blog' ),
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
// adapt the following to suit the formatting and fields of your post.
the_title();
the_content();
}
} else {
// oh no, it didn't work.
}
// Restore original Post Data
wp_reset_postdata();
You'll have to adapt the loop to match whatever layout and structure you're using in single.php or blog-single.php. The concept here is to create a specific archive for the year 2093 and then just do a custom query to return your post.
Just remember to update your code in the year 2093.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With