I’m developing a Custom Post Type plugin, which works fine in dev. Now that I’ve moved it to production, I’m getting a 404 when I try to display the template for the CPT.
So, two questions:
1- Is there some mechanism to determine the path WP took to get through the hierarchy?
2- Why wouldn’t it just give me the single or index page?
I’ve dumped $wp_query and a stacktrace at the end of the 404. Here’s part of what I found:
[query] => Array
(
[page] =>
[pagename] => refletters/proximity
)
[request] => SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND (wp_posts.ID = '0') AND wp_posts.post_type = 'page' ORDER BY wp_posts.post_date DESC
<div class="su-posts su-posts-default-loop ">
<div id="su-post-171198" class="su-post ">
<h2 class="su-post-title"><a href="https://magenaut.com/angularjs/angularjs-can-you-rename-a-service-without-modifying-its-core-source/" rel="nofollow noreferrer noopener">AngularJS – can you rename a service without modifying its core source?</a></h2>
<div class="su-post-meta">
Posted: August 4, 2022 </div>
<div class="su-post-excerpt">
All we need is an easy explanation of the problem, so here it is. I have a situation where I’ve downloaded a written service for angular.js, and it works fine – but I would prefer to have it called something different in my code just for the convenience and readability. It isn’t really a requirement, […]
</div>
<a href="https://magenaut.com/angularjs/angularjs-can-you-rename-a-service-without-modifying-its-core-source/#respond" rel="nofollow noreferrer noopener" class="su-post-comments-link">0 comments</a>
</div>
<div id="su-post-171200" class="su-post ">
<h2 class="su-post-title"><a href="https://magenaut.com/angularjs/express-angular-routing-causing-infinite-loop-crash/" rel="nofollow noreferrer noopener">Express + Angular routing causing infinite loop + crash</a></h2>
<div class="su-post-meta">
Posted: August 4, 2022 </div>
<div class="su-post-excerpt">
All we need is an easy explanation of the problem, so here it is. I’m working on a Node app using Express as well as Angular. I’m using Angular for routing and have my routes setup like so: app.config([‘$routeProvider’, function ($routeProvider) { $routeProvider.when(‘/’, { templateUrl: ‘/partials/main’ //controller: ‘IndexController’ }).when(‘/discover’, { templateUrl: ‘/partials/discover’ }).when(‘/user/home’, { //HERES […]
</div>
<a href="https://magenaut.com/angularjs/express-angular-routing-causing-infinite-loop-crash/#respond" rel="nofollow noreferrer noopener" class="su-post-comments-link">0 comments</a>
</div>
<div id="su-post-171196" class="su-post ">
<h2 class="su-post-title"><a href="https://magenaut.com/angularjs/how-to-manually-toggle-angular-ui-select-dropdown/" rel="nofollow noreferrer noopener">How to manually toggle angular-ui-select dropdown</a></h2>
<div class="su-post-meta">
Posted: August 4, 2022 </div>
<div class="su-post-excerpt">
All we need is an easy explanation of the problem, so here it is. I’m using AngularUI’s ui-select to create several multiselects on a page. I need to be able to open the dropdown list when a user clicks on a button on the page. I’ve tried using jQuery’s .click() and .toggle(‘click’) on the element, […]
</div>
<a href="https://magenaut.com/angularjs/how-to-manually-toggle-angular-ui-select-dropdown/#respond" rel="nofollow noreferrer noopener" class="su-post-comments-link">0 comments</a>
</div>
<div id="su-post-171169" class="su-post ">
<h2 class="su-post-title"><a href="https://magenaut.com/angularjs/how-to-require-at-least-1-checkbox-for-angularjs-form-validation/" rel="nofollow noreferrer noopener">How to require at least 1 checkbox for AngularJS Form Validation?</a></h2>
<div class="su-post-meta">
Posted: August 4, 2022 </div>
<div class="su-post-excerpt">
All we need is an easy explanation of the problem, so here it is. I have an array of JSON objects which is displayed in a form. I would like to have the form validation work where a user has to select at least one checkbox for the entire form to be valid. I know […]
</div>
<a href="https://magenaut.com/angularjs/how-to-require-at-least-1-checkbox-for-angularjs-form-validation/#respond" rel="nofollow noreferrer noopener" class="su-post-comments-link">0 comments</a>
</div>
<div id="su-post-171149" class="su-post ">
<h2 class="su-post-title"><a href="https://magenaut.com/angularjs/how-can-i-use-numbers-with-angular-js-without-comma-and-dot/" rel="nofollow noreferrer noopener">How can I use numbers with angular.js without comma and dot?</a></h2>
<div class="su-post-meta">
Posted: August 4, 2022 </div>
<div class="su-post-excerpt">
All we need is an easy explanation of the problem, so here it is. I m new at angular.js I have a ID column in my grid so I dont want to use formatted numbers with comma or dot. Should I use replace method or related regex expression? I used like: {{value | number: 0}} […]
</div>
<a href="https://magenaut.com/angularjs/how-can-i-use-numbers-with-angular-js-without-comma-and-dot/#respond" rel="nofollow noreferrer noopener" class="su-post-comments-link">0 comments</a>
</div>
<div id="su-post-171150" class="su-post ">
<h2 class="su-post-title"><a href="https://magenaut.com/angularjs/how-to-customize-angular-datatables-style/" rel="nofollow noreferrer noopener">how to customize angular-datatables' style</a></h2>
<div class="su-post-meta">
Posted: August 4, 2022 </div>
<div class="su-post-excerpt">
All we need is an easy explanation of the problem, so here it is. I’m new to angular, trying to use angular-datatables library http://l-lin.github.io/angular-datatables/#/angularWay, but don’t know how to control the style of the table, cause they are all angular directives, is it possible I can touch the HTML elements inside? like the example below, […]
</div>
<a href="https://magenaut.com/angularjs/how-to-customize-angular-datatables-style/#respond" rel="nofollow noreferrer noopener" class="su-post-comments-link">0 comments</a>
</div>
<div id="su-post-171185" class="su-post ">
<h2 class="su-post-title"><a href="https://magenaut.com/angularjs/angular-module-factory-is-not-a-function-after-concat-gulp/" rel="nofollow noreferrer noopener">Angular module().factory() is not a function after concat (gulp)</a></h2>
<div class="su-post-meta">
Posted: August 4, 2022 </div>
<div class="su-post-excerpt">
All we need is an easy explanation of the problem, so here it is. Trying to concat/uglify my angular app using gulp for the last few hours, i have stripped down whole process to simple concat, and even removed angular file from concat process to a separate <script> request in header – and still, I […]
</div>
<a href="https://magenaut.com/angularjs/angular-module-factory-is-not-a-function-after-concat-gulp/#respond" rel="nofollow noreferrer noopener" class="su-post-comments-link">0 comments</a>
</div>
<div id="su-post-171178" class="su-post ">
<h2 class="su-post-title"><a href="https://magenaut.com/angularjs/how-to-prevent-nginfinitescroll-from-being-triggered-multiple-times-after-the-initial-trigger/" rel="nofollow noreferrer noopener">How to prevent ngInfiniteScroll from being triggered multiple times after the initial trigger?</a></h2>
<div class="su-post-meta">
Posted: August 4, 2022 </div>
<div class="su-post-excerpt">
All we need is an easy explanation of the problem, so here it is. I am using ngInfiniteScroll to enable infinite scrolling on my website. It works partly as expected, once I scroll to the bottom of the page it calls the method I want it to call to show more posts, except that it […]
</div>
<a href="https://magenaut.com/angularjs/how-to-prevent-nginfinitescroll-from-being-triggered-multiple-times-after-the-initial-trigger/#respond" rel="nofollow noreferrer noopener" class="su-post-comments-link">0 comments</a>
</div>
<div id="su-post-171176" class="su-post ">
<h2 class="su-post-title"><a href="https://magenaut.com/angularjs/how-to-translate-a-date-object-using-angular-translate/" rel="nofollow noreferrer noopener">How to translate a date object using angular-translate?</a></h2>
<div class="su-post-meta">
Posted: August 4, 2022 </div>
<div class="su-post-excerpt">
All we need is an easy explanation of the problem, so here it is. I have a list of date in my view, powered by my controller. I am using angular-translate to manage localisation in my all application but do not know how to deal with date object. My HTML looks like this : <div […]
</div>
<a href="https://magenaut.com/angularjs/how-to-translate-a-date-object-using-angular-translate/#respond" rel="nofollow noreferrer noopener" class="su-post-comments-link">0 comments</a>
</div>
<div id="su-post-171189" class="su-post ">
<h2 class="su-post-title"><a href="https://magenaut.com/angularjs/how-to-show-dependent-select-boxes-options-in-angular-js/" rel="nofollow noreferrer noopener">How to show dependent select boxes options in angular js</a></h2>
<div class="su-post-meta">
Posted: August 4, 2022 </div>
<div class="su-post-excerpt">
All we need is an easy explanation of the problem, so here it is. I have a form and I want to have two select boxes so that in one of them certain options would show/hide based on the current value of another select box. e.g Select box X Options : A B Select box […]
</div>
<a href="https://magenaut.com/angularjs/how-to-show-dependent-select-boxes-options-in-angular-js/#respond" rel="nofollow noreferrer noopener" class="su-post-comments-link">0 comments</a>
</div>
</div>
=> Array
(
)
[queried_object] =>
[queried_object_id] => 0
And the stack trace:
2013-04-27 22:16:41 - 24.52.197.40 - TRACE - index.php - 404.php[39] -
wordpress/wp-content/themes/notoriousconsultant/404.php[39] - aaLog->logtrace
wordpress/wp-includes/template-loader.php[50] - include
wordpress/wp-blog-header.php[16] - require_once
wordpress/index.php[17] - require
Thanks for your help.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Always flush the rewrite rules when you register a new public post type or taxonomy. Otherwise the internal rewrite rules will not take that into account when an URL is mapped to a query.
You can automate that process by hooking into registered_post_type and registered_taxonomy.
Below is the updated code, based on feedback from comments and other people.
Download as plugin T5 Silent Flush on GitHub.
add_action( 'registered_post_type', 't5_silent_flush_cpt', 10, 2 );
add_action( 'registered_taxonomy', 't5_silent_flush_tax', 10, 3 );
/**
* Flush rules for custom post types.
*
* @wp-hook registered_post_type
* @param string $post_type
* @param stdClass $args
* @return void
*/
function t5_silent_flush_cpt( $post_type, $args )
{
if ( $args->_builtin )
return;
if ( ! $args->public )
return;
if ( ! $args->publicly_queryable )
return;
if ( ! $args->rewrite )
return;
$slug = $post_type;
if ( isset ( $args->rewrite['slug'] ) && is_string( $args->rewrite['slug'] ) )
$slug = $args->rewrite['slug'];
$rules = get_option( 'rewrite_rules' );
if ( ! isset ( $rules[ $slug . '/?$'] ) )
flush_rewrite_rules( FALSE );
}
/**
* Flush rules for custom post taxonomies.
*
* @wp-hook registered_taxonomy
* @param string $taxonomy
* @param string $object_type
* @param array $args
* @return void
*/
function t5_silent_flush_tax( $taxonomy, $object_type, $args )
{
// No idea why we get an array here, but an object for post types.
// Objects are easier to write, so ...
$args = (object) $args;
if ( $args->_builtin )
return;
if ( ! $args->public )
return;
if ( ! $args->rewrite )
return;
$slug = $taxonomy;
if ( isset ( $args->rewrite['slug'] ) && is_string( $args->rewrite['slug'] ) )
$slug = $args->rewrite['slug'];
$rules = get_option( 'rewrite_rules' );
if ( ! isset ( $rules[ $slug . '/(.+?)/?$'] ) )
flush_rewrite_rules( FALSE );
}
This will flush the rules each time you create a new post type or taxonomy. No need to visit the permalink settings again.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0