0

I have built a new site based on a content from an old one. Also, there is some partial content in another WordPress blog which I have to import. Unfortunately, on the blog I don't have full access, but the owner shared the full backup file. I needed only some categories, not the entire blog.

So, I tried to import the file in a brand-new website, on a subdomain, but the export file was too big and the settings of the server didn't allow me to import the file (shared hosting). I've created another blog on wordpress.com, and I've imported the site there. After, I've exported only the necessary category. Unfortunately also having only few articles in the exported file, I couldn't import it because the import was crashed/blocked. The last solution was to import the articles manually. Bad and awful, I know. Anyway, I've started to import them and set the date to its original date in the blog, in the past.

On the newly created site, I've created a new permastruct to allow filtering the loop by category and year

$wp_rewrite->add_rewrite_tag("%muz_category_name%", '([^/]+)', "category_name=");
$wp_rewrite->add_rewrite_tag("%muz_year%", '([0-9]{4})', "year=");
$wp_rewrite->add_permastruct( 'category-archive', 'category-archive/%muz_category_name%/%muz_year%', array( 'walk_dirs' => false, 'paged' => true ) );

These links are working well, but for the year 2021 where I receive a 404. When I check the query, the year is added as the name argument, not the year.

Is this something that can be linked to the fact that the date of the post is set back in history? I checked the records in DB and I haven't found anything strange between these old posts and the newly created ones.

Also, I don't understand why I receive a 404 response. I expect something like "No posts found on provided criteria" or something like that. As I said, this happens only for year 2021. For the rest of the years, until 2012 everything works well.

So, trying the URL /category-archive/expozitii-temporare/2022 will search in the category Expoziții temporare filtered by year 2022. WP Query object looks like this:

[query] => Array
    (
        [year] => 2022
        [category_name] => expozitii-temporare
    )

Using /category-archive/expozitii-temporare/2021 the WP Query object returns:

[query] => Array
    (
        [category_name] => expozitii-temporare
        [page] => 0
        [name] => 2021
    )

In fact, what I want is to alter main Loop Query to filter posts by category and year and still have a friendly URL.

Any starting point is much appreciated, so...

Thanks in advance!

3
  • I tried now to get posts only by year using URL /2021/ which is a default WP functionality and still returns 404, but, if I use any other year it works, so basically the problem is not in the permalink, the problem is somewhere else. Any clues?
    – pictoru
    Apr 18, 2022 at 14:48
  • I've created a staging site, deactivated all plugins, switched back to original theme (from the child theme) so I could say everything was nearly just born apart from the content. The issue persists, so it must be some WP bug?
    – pictoru
    Apr 18, 2022 at 15:29
  • I posted a similar question on stackoverflow.com. I found something eventually. stackoverflow.com/q/71866175/824611 It doesn't solve my issue but is a workaround.
    – pictoru
    Apr 19, 2022 at 7:19

1 Answer 1

0

Having the permalink as /%postname%/ it doesn't work either if I switch back to the original WP theme and disable all plugins. It works though if I change the permalink to the predefined /%year%/%monthnum%/%postname%/ or to a custom /%year%/%postname%/ permalink. From my point of view, it is a WP bug.

Your Answer

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

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