Hot answers tagged 404-error
11
This is my first time participating here on Stack Exchange, but I'll give this a go and see if I can help point you in the right direction.
By default, hierarchical CPTs behave exactly the way you've described. The unique slug prefix, "newsletter" in this case, is to let the rewrite engine know how to tell requests for different post types apart.
Those CPT ...
4
By the time you reach the template, WordPress has already queried the database and decided what to display based on those results.
You're seeing a 404 error because based on the default main query, there are no more posts to show.
When you call query_posts in the template, you overwrite that original query. Despite the fact that your new query results ...
3
I don't think there's anything fundamentally wrong with your approach, I see it pretty often.
You could hook parse_request and 301 redirect any requests to footer to the front page. I wonder though how visitors would end up there in the first place, as long as you exclude it from the sitemap and don't link to it anywhere.
Or you could create a custom post ...
3
It stopped to work with WP 3.4 because there was fixes to handle_404(), and You are using wrong way on homepage... instead of creating new query, modify main query.
Changeset: http://core.trac.wordpress.org/changeset/19892
Sample code:
function my_query_for_homepage( $query ) {
if( $query->is_main_query() && $query->is_home() ) {
...
3
You should be using a filter outside of your template for this:
add_filter( 'template_include', 'wpa62226_template_include', 1, 1 );
function wpa62226_template_include( $template ){
if( is_page( 'some-page' ) ) :
global $wp_query;
$wp_query->set_404();
status_header( 404 );
$template = locate_template( '404.php' );
...
3
Never use query_posts() :). See this answer for more detailed explanation of why not, and the alternatives.
In this instance, remove your query_posts() and instead in a plug-in, (or functions php).
add_action('pre_get_posts','wpse57229_change_query_for_main_page');
function wpse57229_change_query_for_main_page( $query ){
if( ...
3
The parent/Child permalink Works out of the box as long as you set
'hierarchical'=> true,
'supports' => array('page-attributes' ....
Update:
I just tested it again and it works as expected, with this test case:
add_action('init','test_post_type_wpa77513');
function test_post_type_wpa77513(){
$args = array(
'public' => true,
...
3
You could try the Wordpress function set_header() to add the HTTP/1.1 404 Not Found header;
So your Code 2 example would be:
function rr_404_my_event() {
global $post;
if ( is_singular( 'event' ) && !rr_event_should_be_available( $post->ID ) ) {
global $wp_query;
$wp_query->set_404();
status_header(404);
}
}
add_action( ...
2
Although I'm not a big fan of godaddy, it's not necessarily a godaddy problem. Happened to me on sites hosted at godaddy and Bluehost. If you are getting the yoursite.com/wp-admin/upgrade.php?_wp_http_referer=%2Fwp-admin%2F error, this worked for me:
Navigate via FTP to your installation. Check to see if the
upgrade.php file is there.
If not, download ...
2
I've seen this happen before -- Jake makes one good suggestion and I've had to do just that to resolve the issue in several cases.
Another potential fix is to temporarily rename your /wp-content/themes folder (to something like themes.bak) and try to navigate directly to /wp-admin -- there is a chance that a customization to the theme is causing an ...
2
The first thing to try:
Manually download a fresh copy of Wordpress
Log into the FTP account and upload everything EXCEPT the wp-content folder
It is important that you do NOT copy over the wp-content folder or the wp-config.php files. These are custom to each site.
This will allow you to make sure the upgrade is complete.
If that doesn't work, you ...
2
Martin's fix works, but a better solution is to use the pre_get_posts function.
Example:
function custom_type_archive_display($query) {
if (is_post_type_archive('custom_type')) {
$query->set('posts_per_page',1);
return;
}
}
add_action('pre_get_posts', 'custom_type_archive_display');
2
WordPress has a function to send a different status header:
status_header( 200 );
If you send that after WordPress has send its headers and before you print anything you will get a status header 200.
You could also filter 'status_header' and change the value there. See wp-includes/functions.php for details.
2
Remove the 'fastcgi_intercept_errors' argument from you configuration. It's unnecessary since 'error_page' declares 404 errors, which should be handled by index.php, which will trigger PHP-FPM to handle it, and WordPress to present your theme's 404 page.
It seems counter-intuitive, but 'fastcgi_intercept_errors' is actually causing PHP not to handle the ...
2
function generate_404_somehow() {
global $wp_query;
$wp_query->is_404 = true;
}
add_action('wp','generate_404_somehow');
Of course, that will send all of you page to the 404 template. I don't know what the conditions are that this should fire or not fire.
Or to be more cautious (see comments) ...
function generate_404_somehow() {
global ...
2
The 404.php template file is used for 404 errors: i.e. no posts found.
Since there are no posts, there is no $post object. With no $post object, functions such as the_ID() are not available, and will return the error you're observing.
The fix: replace all instances of $post-derived data with static data. e.g. replace this:
<div id="post-<?php ...
2
You can use the locate_template() function to include the 404 template. Remember to do this instead of using get_header() or generating any output; otherwise you will have a duplicate.
<?php
if ( ! $myVar ) {
status_header(404);
global $wp_query;
$wp_query->is_404 = true;
locate_template('404');
return;
}
// otherwise, show the ...
2
Two options:
Use conditional code inside of 404.php, to output different content/markup for the post-type
Intercept the template at template_redirect, and include a separate template file for a 404 for the post-type.
Personally, I'd go with option 1, as it is easier and more intuitive.
2
Step 1, add the rewrite tags for custom event year and month query vars, then register the event post type with those tags in the slug argument of the rewrite argument:
function wpa83531_register_event_post_type(){
add_rewrite_tag('%event_year%','(\d+)');
add_rewrite_tag('%event_month%','(.+)');
register_post_type( 'event',
array(
...
2
Checkout the WordPress Template Hierarchy page, in particular the diagram: http://codex.wordpress.org/Template_Hierarchy#Visual_Overview
In short though the answer is no, the 404.php is only used when the URL does not resolve to any other template type.
2
I wouldn't recommend forcing a 404.
If you're worried about search engines why not just do a "no-index,no-follow" meta on those pages and block it with robots.txt?
This may be a better way to block the content from being viewed
add_filter( 'template_include', 'nifty_block_content', 99 );
function nifty_block_content( $template ) {
if ( is_singular( ...
2
Use a later action hook
You cannot use Conditional Tags before the posts_selection hook has run (as per the codex), which happens right after pre_get_posts and quite a bit after init.
Hence, would it not be easier to set the cookie at a later stage of the request, rather than attempting to detect the 404 earlier (which, off the bat, I would not know how)?
...
1
Use wp_mail(), not just mail(). It is a wrapper for PHPMailer, a class that takes care for many problems the native mail() function often gets.
See my plugin 404 Tools for how to use it in this case. To send an HTML email see Milo’s answer to a related question.
1
I am assuming that the stuff in "def/products" is not handled by WordPress.
Try reversing the index.php and abc/products rules, like so:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^abc/products-(.+)$ def/products-$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond ...
1
Because it is looking for the page 404, which is a child of the page /error. Try just doing this:
function show_404($message = 'page not found'){
wp_redirect(home_url() . '/error?m=' . urlencode($message));
exit();
}
But your doing it wrong.
You should just use WordPress's internal 404 page, it will save a lot more headaches that will arise in the ...
1
Try this instead:
function has_shortcode($shortcode = '') {
global $post;
// false because we have to search through the post content first
$found = false;
// if no short code was provided, return false
if ( !$shortcode ) {
return $found;
}
if ( is_object( $post ) && stripos( $post->post_content, '[' . $shortcode ) !== false ) {
...
1
Relevant:
http://core.trac.wordpress.org/ticket/12002
/blog/ is added to prevent permalink clashes on the root site of a multisite install. For now you're going to have to resort to using the network admin and manually wading through the options table modifying it each time you regenerate rewrite rules.
You can remove the blog slug completely.
Go ...
1
Sounds like an easy task to do. I think hooking into 'template_redirect' and conditionally triggering redirect is the way to go.
EDIT: Seems is_tag() isn't reliable once 404 is triggered. That's why we need to look into the query vars to figure out if it's really a tag query or not.
function redirect_404_tags_wpse67077() {
global $wp;
if ( ! empty( ...
1
I ran a patch in GoDaddy found in the WP application section of my GoDaddy hosting manager. Turns out when I upgraded a plugin, the upgrade.php file was completely deleted from the WP-Admin folder. I just downloaded a fresh copy of WP 3.4.2. I uploaded ONLY the missing upgrade.php file (I still had the upgrade-functions.php file) in my WP-Admin folder. ...
1
Using query_posts is not advised anymore and in your instance, using it outside of a page template will cause strange results, query_posts is used for altering the main loop of your site, therefore its advised to use something like WP_Query instead.
Replace from line 14 of your code:
<?php
//bad: do not use query_posts
global ...
Only top voted, non community-wiki answers of a minimum length are eligible