I've used CPT UI to create a few custom post types on a real estate website, one of which is called "team". It's worked fine up until recently... Older team entries show up as expected, both in the list/archive view and the single view. However, we've recently added a new team member entry and discovered that only the single view causes a "page not found" error. After more testing it turns out that any new entry to the "team" post type causes an error in the single view only -- they pop up in the archive view just fine.

Just to be clear: the older team entries all display as they should in both archive and single view. Any new team entries show in the archive view, but cause a 404 in the single view.

I've tried re-saving the permalink settings, using plain permalink settings, flush_rewrite_rules(), and I've checked for any slug conflicts. I'm totally stumped.

UPDATE: After some debugging as recommended (thank you!) I think I've found the problem... The page request is using an old meta key in the query vars that isn't present in new entries. Somehow, WordPress is internally using the meta key 'agent_last_name' when it should be using 'agent_alpha_name'. I'm guessing I need a way to force this to refresh?

  • Try my plugin - debug-bar-rewrite-rules (you totally can use it without debug bar), at least you will be able to check what rules you have and if url you are geting with 404, really match any of the rules you have. Apr 20, 2018 at 5:16
  • Active the WP_DEBUG constant to get error messages, maybe this helps you.
    – bueltge
    Apr 20, 2018 at 8:18
  • Thank you both -- debugging had totally slipped my mind. I've updated my question with the latest findings. Apr 20, 2018 at 14:47

1 Answer 1


So I was digging a lot deeper into my child theme and found that I was actually the culprit... At some point early on I had written a function using pre_get_posts to force a custom sort order on the team custom post type. Here's what I found hiding out:

add_action('pre_get_posts', 'gpc_agent_pre_get_posts');
function gpc_agent_pre_get_posts( $query ) {
    // do not modify queries in the admin
    if( is_admin() ) {
        return $query;
    // only modify queries for 'agent' post type
    if( isset( $query->query_vars['post_type'] ) && $query->query_vars['post_type'] === 'team' ) {
        $query->set( 'orderby', 'meta_value' ); 
        $query->set( 'meta_key', 'agent_last_name' );    
        $query->set( 'order', 'ASC' ); 
    // return
    return $query;

I've removed that and all is well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.