If you want to force the 404.php
template to load if there are no found posts, use the template_include
filter:
function wpa84794_template_check( $template ) {
global $wp_query;
if ( 0 == $wp_query->found_posts ){
$template = locate_template(
array( '404.php', $template ),
false
);
}
return $template;
}
add_filter( 'template_include', 'wpa84794_template_check' );
Related Posts:
- What is This esc_html_e() i wordpress php?
- How to get URL of current page displayed?
- How to create custom 401, 403 and 500 error pages?
- Getting only direct child pages in WordPress with get_pages
- Query multiple custom post types in single loop
- How can I fetch loop of post titles via AJAX?
- WordPress GET parameters causing 404 Not Found
- Inject post (from specific category) between posts in Loop
- Knowing the total number of posts before to get into the loop
- Why would a GET variable one one page of a site cause a 404 error when a GET variable works on another page of a site?
- get product attributes for current product and store it in a variable
- Build a content and excerpt grid loop with paging and options for # of posts
- Displaying post per day
- Question about repurposing WordPress 404 handler
- Installing wp3.2.1 on IIS; getting empty sessions
- Guidance with The Loop for CMS
- Display only text to WordPress loop without loosing the text formatting
- How to loop over custom fields in a page template?
- How to add active class to custom menu using while loop and wp_list_pages
- Want to separate sections of posts. Can you restart loop?
- MySQL query performed 4 times inside loop
- Print html when custom field has value inside while loop
- Alter secondary loop to exclude posts from current page category
- Result of Custom WP_Query appears on 404 Page (but result are found!)
- Post from one loop in different containers?
- Custom Loop Pagination on WordPress
- Specific Loop For 2 Within Each
- delete an array element when its date expires
- Two posts in same div – WP loop
- Infinite-Scroll Plugin and Jetpack Infinite Scroll Plugin – Adding to “Thoughts” Theme
- How to change post count in wordpress loop?
- How can I loop into two different DIVS without repeating the DIVs
- User Defined order on get_categories?
- Woocommerce, recognize the loop of related products
- Store loop into array
- Looping through WP_Post Object
- WordPress loop specific thumbnail size
- get understrap pagination to work with custom query
- Woocommerce – How to get products which have a sale between 20% to 40%? [closed]
- Displaying Only Certain Tags in Loop
- there’s a way to include a minimal WP for check only the current user, its roles (caps?) and then release/free it?
- Easiest way to show total number of subpages
- Custom Loop through category menu to include sub categories
- When would you use $_post instead of $post?
- Output 2 items within the Loop
- How do I display the function the_content in this loop?
- Show Custom Taxonomy Title
- How to exclude specific category from the get_the_category(); array
- Way to display “Yesterday”, “Today”
- How can i display post loop in table format?
- spliting posts into two columns
- Must Use Plugin Causing Query Error
- How to get to a specific position in wp_query?
- Advanced Custom Fields: Post Object – Not returning data [closed]
- How to speed up a wordpress function with multiple loops?
- Facebook “like” open graph meta in header.php
- Custom excerpt function re-factoring
- How can I show the post thumbnail from the most recent of a certain post type, in widget?
- multiple if statements [closed]
- How to select WooCommerce products by post_meta and order them
- How can I add pagination and how can I change thumbnail size?
- How to Display a Single Post Excerpt
- have_posts() execution failure
- How does the ternary operator work in the wordpress loop post?
- $wpdb->flush(); breaks the loop
- Use object in template part
- Get first URL from post content
- How can I add multiple ‘tax_query’ arrays via a loop?
- ACF page while loop breaks footer while loop
- WordPress does not load page.php, return 404.php
- Using foreach loop breaks
- Cannot display or echo alt text on featured image
- Using Advanced Custom Fields to create a per page slider
- Split loop into two columns, how to favor one side over the other
- WordPress Search Results for Multiple Post Types
- Changing layout with wp_customise
- Dynamic Stylesheet loads but doesn’t finish
- Filter Select results based on selection
- Using loop pagination on single.php
- Loop with slider (slider not loading)
- How to hide all child pages with post_query?
- How to sort posts based on the value (number) of a post’s metadata?
- Show css depending on activity type in BuddyPress activity-loop [closed]
- Why my filterable portfolio page work not perfectly between slug button and slug output WORDRPESS?
- Cannot access wp-admin/wp-login.php (WordPress backend) anymore, what could be wrong?
- Iterate through posts based on array of categories
- get author_name from queried post
- Displaying Woocommerce Product Category in WordPress
- Repeating admin-ajax.php not found error in admin
- How can I add extra word in permalink when someone click download button?
- Increase offset while looping
- Blog posts repeat
- How to add condition in wordpress loop? [closed]
- Woocommerce : Can’t get product info in loop
- How to set variable, pass it to a partial file and remove it after?
- how to refresh div on template part?
- Alert Bar section within WP loop is displaying even though there are no posts
- remove post that has no content
- Display category name only once inside loop
- Can’t find infinite loop cause