Tag Info

Hot answers tagged

15

I was able to display a 404 error by using the following code in my header. <?php global $wp_query; $wp_query->set_404(); status_header( 404 ); get_template_part( 404 ); exit(); ?> To break it down: $wp_query->set_404(): tells the wp_query this is a 404, this changes the title status_header(): sends a HTTP 404 header ...


12

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 ...


11

After a bit more slogging through code and Googling, I found the answer. It's contained in this thread (see Otto42's post), but for the record, adding the following to your plugin will override the 404 handling for the conditions you specify: add_filter('template_redirect', 'my_404_override' ); function my_404_override() { global $wp_query; if ...


11

I could be wrong, but I vaguely remember that: name, email get hijacked by WordPress to do post comments, if you renamed the form elements to be contact-name and contact-email, do you get the same issue?


9

I'm assuming that you put WordPress in your site root and the external directories are also in your site root. The reason this is happening is that .htaccess files follow a hierarchy. Whatever directives are in the top-level .htaccess file flow down and apply to all directories below it. If this is the case, you can do one of several things: Move your ...


9

I would use the wp_title filter hook: function theme-slug_filter_wp_title( $title ) { if ( is_404() ) { $title = 'ADD 404 TITLE TEXT HERE'; } // You can do other filtering here, or // just return $title return $title; } // Hook into wp_title filter hook add_filter( 'wp_title', 'theme-slug_filter_wp_title' ); This will play ...


7

This has worked for me in the past for a similar situation : Put this on top of .htaccess ErrorDocument 401 default


6

There is a method specifically for this: function my_parse_query( $wp_query ) { if ( $wp_query->get( 'my_custom_var' ) > 42 ) $wp_query->set_404(); status_header( 404 ); } add_action( 'parse_query', 'my_parse_query' ); That should load the 404.php template in your theme, if you have it. Otherwise, it will fall back to ...


6

The posts_per_page refers to how many posts per page, and not what page you are viewing. For that, you want to set the paged argument. See the Codex on WP_Query and this article by Scribu. With the paged argument set, it'll return the appropriate posts depending on the page number (the first x posts for page 1, the next x posts for page 2 etc). If not, you ...


6

Put <?php if( !is_404() ) : ?> before your navigation and <?php endif; ?> after your navigation and VIOLA! It's gone!


5

Problem solved. The plugin "User Access Manager" was found guilty of inserting a .htaccess file into wp-content/uploads/ and not handling calls properly afterwards. I don't know how UAM plugin could be fixed, but It's ok to remove the .htaccess file. Nothing else depends on it. (at least in my case)


5

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( ...


4

The only way to debug this is to disable one plugin at a time, each time trying to reproduce the problem before you disable another plugin. Start with the plugins that have anything to do with the administration of WP, then move down to regular theme plugins, widgets and such. Inspect the "Not Found" page that you are served better (browse with Opera and ...


4

It's bad practice to do so purely because the Search Results page was found it just returned no results. A 404 would be used if the search page didn't exist.


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 ...


4

You don't need to add anything special to the top of 404.php. WordPress will know to use 404.php automatically when it tries to get a post or page and fails. To create a custom 404 page for a theme, the simplest way is to: Copy the index.php file from the current theme to a file called 404.php. Edit your new 404.php to delete the code dealing with ...


3

Headers are sent long before you try to alter them. Headers are sent by actions associated with get_header(), so by the time your code executes, it is too late to alter the headers. You can demonstrate this with a simple experiment. Try each of the following: get_header(); status_header( 404 ); and status_header( 404 ); get_header(); In a template ...


3

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');


3

This is challenging, because showing something would require page not to be private. It is more common to leave page public, but make it produce conditional output depending on if user is logged (is_user_logged_in()) in or other criteria.


3

Creating a secondary query or overwriting the main query inside a page template is the quickest and easiest way I know to break pagination. The main query, which determines which page to load runs before your template thus the results on the page and the query that loads the page become out of sync. The main query does not know about your in-template ...


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 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

Check to make sure your .htaccess file (in the root) is writable by WordPress, if it isn't then you may need to manually set this up to get the permalinks working correctly.


3

Without testing, I'll guess this has nothing to do with the author names specifically, but the fact that author is a built in WordPress query var, and /author/author-name/ is the default permalink for author archives. Change your post type name so the query var no longer clashes, then either change your post type rewrite slug, or change the the default slug ...


3

You should definitely avoid the public WordPress query vars: attachment attachment_id author author_name cat category_name comments_popup day error feed hour hour m minute monthnum name p page_id paged pagename post_parent post_type preview second static subpost subpost_id tag tag_id tb w year There's also this list of reserved terms, inexplicably located ...


3

Edit file wp-config.php in root & define site url and home url: define('WP_HOME','http://example.com'); define('WP_SITEURL','http://example.com'); And go to admin dashboard and update permalink (Settings => Permalinks => Update).


3

Jan Fabry wrote a very useful plugin that I think it would be helpful for you to analyze your rewrite rules.


3

I needed to do the same for a custom project where there was always a 200 page, and found you can also simply add this to the top of your template file ( above get_header(); ) global $wp_query; status_header( 200 ); $wp_query->is_404=false;


3

You're probably using an input field that contains name="name". A lot of generic words are used by WordPress itself (incl. name, so a best practise is to always prefix_ your fields, like name="prefix_name".


3

Yea, you need to flush the permalinks. This helps solve the problem even further. 'rewrite' => array("slug" => "products"), // Permalinks format I was getting the same problem when using 'rewrite' => true,



Only top voted, non community-wiki answers of a minimum length are eligible