The script never hits a 404 so it continues to load.
If I am looking at this correctly it won’t ever hit a 404, and it shouldn’t ever hit a 404
.
You are loading a page template, the finding and loading of which is going to be done by the main query. That page is always going to be found– ie, not 404
.
Your secondary query– the one that is loading the posts– is inside the page template. It doesn’t matter if there are posts or not, it won’t trigger a 404
. That part is long past by the time the secondary query runs.
I think this is fundamentally just a design problem.
I don’t know how your AJAX works, but what you should be doing is checking for the presence of posts returned by the query, not for a 404
returned by the page. You stop when you get 0 posts. And you should really be using the AJAX API for this as well.
Related Posts:
- Pagination & get_pages?
- How can I use the WordPress Loop and Pagination in multiple instances but different scenarios throughout my site?
- What is the preferred way to add custom javascript files to the site?
- Does the functions.php file ever get called during an AJAX call? Debug AJAX
- theme path in javascript file
- pass object/JSON to wp_localize_script
- Solutions for generating dynamic javascript / CSS
- How to move page template files like page-{slug}.php to a sub-directory?
- How to move page templates to custom folder?
- Proper, exhaustive documentation for wp.editor etc
- Create “File-less” Page Template in Functions.php
- Any alternate TinyMCE4 themes / subthemes?
- Is it possible to manipulate the list of page templates?
- Adding items to page template dropdown on Page Edit Screen
- Is there a way to set the order of wp_footer hooked functions?
- Google Maps not displaying in wordpress using Google Maps Javascript API
- Trigger Customizer saving process with Javascript only
- Adding Content Areas to Custom Page Template
- What is the best practice for customizing a plugin’s JavaScript/jQuery?
- Trouble with conditional tags
- Changing the entire control choices using wp.customize with JavaScript
- How to Change CSS Variable value in Theme Customizer Live Preview
- Pagination is not working using WP_Query
- Returning Variables back into a template
- Two queries on the same page with pagination
- Modifying JS files in Child-theme
- Page attribute template dropdown not displayed even the syntax is correct
- query posts in wordpress
- posts_nav_link(); not showing up on static pages
- Whats the safest way to output custom JavaScript and Css code entered by the admin in the Theme Settings?
- WordPress Customizer Control with React
- Do I really need the div class entry?
- Get list of months with posts
- Any tag pagination page (except the 1st page) loads index.php template instead of tag.php
- How to configure wordpress to work with Vuejs with SSR and without hashbang
- Page template across themes
- How WordPress converts URL to $query_string
- How to hook CSS file according to theme selection in the customizer section
- Adding default pagination to wordpress loop
- How to correctly add JQuery in a WP theme?
- Why is the first query affecting the second query, even after wp_reset_query() and wp_reset_postdata(), but not on the second page?
- using wordpress without javascript
- Where can I access my custom page template?
- Including Javascript options
- WordPress page templates in a directory
- Disable front-page.php template
- Can I show all the template files that are being used on my site?
- Implement content-nosidebar.php / content-leftsidebar.php
- get_page_template returning nothing
- WordPress with broken paging page 3
- Custom URL parameters in template files
- Metadata Query when storing data as array possible?
- Multiple Page Templates & CSS
- Pagination of a WP_Query Loop in a child-page page template
- JavaScript Change focus to password field login page being reset
- Highest number of WordPress Custom Page Templates?
- paged > max_num_pages won’t throw 404
- jQuery not available to other scripts
- Single Page theme [closed]
- Custom metabox for custom page template
- Get pagination working for custom loops within page templates
- Why is the Page Template dropdown menu using the wrong file name?
- How to make Isotope and WordPress work together?
- Conditional statement to show pagination
- How to add “Template” option in page attributes panel?
- Single page site with history.js
- Keep sticky posts out of query unless they have featured image
- WordPress Pagination changes my template
- How to add material design css in wordpress and woocommerce
- Use second time navigation.js in underscores [closed]
- How to create a custom page(not a template) in a theme
- Theme Javascript.php Overwritten Nightly [closed]
- Template selection area is not visible on page editor sidebar in wordpress twentty sixteen default theme
- How to: JQuery multiple wordpress media uploader buttons in the same options page?
- Move default page templates to sub directory
- How to get javascript slider to work! [closed]
- Custom page template with custom fields
- how to setup custom content structures
- How safe is renovating $wp_query when doing WP_Query pagination in Page Template
- Theme Customizer not loading JS for live preview
- Redirect to another page using contact form 7? [closed]
- How can I conditionally show different home page templates based on whether or not the user is logged in?
- My jQuery is enqueued properly. So why isn’t it working?
- How to query the latest 5 posts and sort them by title?
- Enqueued JavaScript is not working
- Load sidebar template just once to prevent multiple animations
- Need help with adding templates (archives and sitemap) to WordPress child theme
- 2 loops, is_home won’t work, count is off
- How to create first post, fifth post full width, rest in three columns and so on
- Issue On Displaying Pages with Post Name Permalink
- Why in the static pages of my theme are showing these information?
- How to register and enqueue JavaScript files without breaking plugin dependencies?
- wp_enqueue_script not working?
- pagination for a custom loop with multiple post types
- How can I prevent posts with no title showing up in my query?
- CSS class on last post in loop ( custom query )
- Custom Post Type Query issue
- How to order by multiple date meta_values?
- How to create query to get top 3 sticky/latest posts
- Pagination on template page for custom query redirecting to index.php