Custom post url in search.php isn’t the correct rewrited url

Solved, it was an issue with assigned parent- and subcategories.

Because I’m using the ‘WP All Import’ plugin connected to Google Drive, posts are automatically imported. Since some of the posts don’t have categories assign in the Google Drive document, ‘WP All import’ doesn’t assign a category on importing the data.

For some reason this has resulted in duplicate content, importing already existing posts but without a category. Because the latest imported posts are without category and ordered descending by date on the search page, I was under the impression that there was something wrong with the permastructure.