Jump to the code
If you've been using Elementor for any length of time, you'll know that. From time to time, for no apparent reason, you can set up a site with the Post widget to display you know, X number of posts, usually 6 to 9 per page and then load more posts, and it'll work fine for a little while. But for no apparent reason, it'll start getting to the point. Where every time you hit load more or Scroll down the page or hit the paging function, whichever option you choose it just keeps reloading the same. 8 or 9 posts per page, the same posts over and over and over again. It just doesn't go away. You can dig around, you can swap it out, put it back, it just keeps doing it. Well, I recently had this problem on a site we launched earlier in the year and. This suddenly appeared and we couldn't figure it out quickly and because I didn't have the time right then to sort it out. I thought, well, you know what? I pay for a premium Elementor license. Let's let them do some work for me. So I contacted Elementor support.
I went back and forth with Elementary support for about a week to a week and a half, and they finally ended up saying, yeah, we can't seem to find the problem. It looks like something that's glitching somewhere will make a special case out of this and we'll see if we can solve it in a future release of Elementary. Alright, well I need to fix this problem, So what do I do? OK I set it aside for a week cause I had other things I had to do and I came back to it to put some focus time into solving the issue.
I started digging around on the Internet because in truth, every problem you have, someone else has had a problem and in my 25 years of doing this there has only been one time where I was the first one to find a solution to the problem. So somebody else has had it, somebody else has mentioned it, somebody else talked about it. The interesting thing is that the solution isn't always. Where you think you're going to find it.
Meaning that don't discount a stray word here and there in a random post somewhere where somebody had a problem different than you, but similar, and when you start looking at it, you'll see the solutions. And this is how I found this one. People were talking about it, but they weren't talking about it in the same words. I was using and I tripped across a article where somebody else had posted information in the comments.
Well hey, I got this. I found this solution over here which helped me fix my problem, which is where I finally found it and what it turns out when you start looking at this problem and you start looking at the loading of your code on the site using the developer tools and Firefox or Chrome or whatever.
You'll see that every time you hit load more, it's loading the same page of content every time, and it appears to start to load the second the proper page, but then it's redirected back to loading the first page. Turns out it's a broken strange 301 redirect error is what's causing this.
Well, somebody came up with some code that you drop into your functions file. Or if you have a customized plugin you use for custom code, you dropped this code into there and it corrects the problem for now.
This doesn't fix the problem. But it corrects your problem. It's a workaround until Elementor figures out what's causing this. The big takeaway is it solves solves the problem at any rate. Without much further ado, you can find the code below. Take that code, go drop it into your functions file for your child theme. Hopefully you're using a child theme. If you're not using a child theme, you will want to put this into a custom plugin because the next time the theme is updated, it will overwrite your functions file if you're not using a child theme. So anyway, enjoy, hopefully this helps everyone out.
/*** //Add this code to your child theme functions file or to a custom plugin. This is a fix for paging/load more issue of showing the same posts over and over again. This is simply a work around right now for a incorrect 301 redirect happening when trying to use the paging load more to show more articles. */ function pre_handle_404($preempt, $wp_query) { if (isset($wp_query->query['page']) && $wp_query->query['page']) { return true; } return $preempt; } add_filter( 'pre_handle_404', 'pre_handle_404', 10, 2 );
There is another option that sometimes works as below.
/*** //Add this code to your child theme functions file or to a custom plugin. * Fix bug with elementor loop grid within tabs, that breaks pagination via load more (click) or page refresh * The bug causes requests to /page-url/{pagination_no}/ to 301 back to /page-url/ * Why exactly this fixes it is unknown, but taken from here: * https://stackoverflow.com/questions/63552653/fix-pagination-after-wordpress-5-5-update *Open Github on the issue here: * https://github.com/elementor/elementor/issues/21417 */ private function filter404PreHandler(){ add_filter( 'pre_handle_404', function($preempt, $wp_query) { if (isset($wp_query->query['page']) && $wp_query->query['page']) { return true; } return $preempt; }, 10, 2 ); }