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?
- Does the functions.php file ever get called during an AJAX call? Debug AJAX
- theme path in javascript file
- Solutions for generating dynamic javascript / CSS
- Proper, exhaustive documentation for wp.editor etc
- Create “File-less” Page Template in Functions.php
- Trigger Customizer saving process with Javascript only
- Changing the entire control choices using wp.customize with JavaScript
- How to Change CSS Variable value in Theme Customizer Live Preview
- Two queries on the same page with pagination
- Modifying JS files in Child-theme
- 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
- How to configure wordpress to work with Vuejs with SSR and without hashbang
- Page template across themes
- 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?
- 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?
- Multiple Page Templates & CSS
- JavaScript Change focus to password field login page being reset
- paged > max_num_pages won’t throw 404
- Single Page theme [closed]
- 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
- Single page site with history.js
- WordPress Pagination changes my template
- How to add material design css in wordpress and woocommerce
- How to create a custom page(not a template) in a theme
- Theme Javascript.php Overwritten Nightly [closed]
- 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]
- Redirect to another page using contact form 7? [closed]
- My jQuery is enqueued properly. So why isn’t it working?
- How to query the latest 5 posts and sort them by title?
- Load sidebar template just once to prevent multiple animations
- Why in the static pages of my theme are showing these information?
- wp_enqueue_script not working?
- pagination for a custom loop with multiple post types
- 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
- What template file is used for homepage pagination?
- WordPress theme resource won’t load over VPN
- pass wordpress template directory into ajax url call
- Modify available templates (in dropdown)
- theme-independent CSS/JS files
- Javascript development in Custom Themes
- Pagination fuction in shortcode always displays on top
- tag__in does not return posts
- Pagination and multiple loops
- How to use shortcode inside of shortcode in theme
- Best practice for implementing a blog page / section in wp_menu_nav()
- Pagination don’t work with active filters
- getBoundingClientRect() showing different values on load vs scroll
- wordpress script_loader_tag in function.php
- Load more posts using AJAX based on posts inside WP_Query
- How to diagnose wp-env environment problem
- A Reviews Page is Showing root Index.php instead of Template-Page
- No templates for condition page.php Elementor
- White screen of death on index.php page 3 and above?
- Show Yoast SEO meta tags in Custom WordPress Templates (Theme)
- How to show metabox on page if it is using a template
- Template for front page (latest posts)
- control posts order by select option
- Problem with Displaying Custom Theme Page’s Content
- Customizer Image-Picker Preview Not Working
- Second page of archive is empty
- How to show children pages as array
- Different stylesheet for different pages not working fully
- How to Apply Category Filter to Pagination
- Why WordPress gets old templates code instead of the last updated ones
- Pagination is not working on custom query inside a custom home page template
- Theme customizer live preview JS- Trying to bind to an html image url without luck
- wp_deregister_script was called incorrectly
- Using wp_enqueue_script with social media buttons?
- wp_enqueue_script causes page to vanish
- How to reuse parts of WordPress site e.g. header, footer, part of header for multiple WordPress sites?
- Pagination adds product to cart Woo-Commerce
- Loop inside page template not working
- pagination/prev and next page links not showing
- Theme now uses require.js and enqueue script no longer works
- WP site makes mobile browser crash for high memory usage
- How to split the site’s layout without damaging this layout? [closed]
- Is there a way to have WordPress autodetect page templates in the page-templates directory and any sub-folders?
- What is the point of using the front-page.php template? [closed]
- jQuery Snippet Not Working on WordPress Site [closed]
- WP Customizer get control value on change
- Execute javscript when theme customizer loads (autosave issue)
- Is there any halfway decent documentation on the wp.media JS class?