|

WordPress Custom Post Types: Fixing 404 Errors, Pagination, and ACF Issues

WordPress Custom Post Types: When They Break

Custom Post Types power complex WordPress sites β€” from portfolios to course platforms. But they can be the source of frustrating bugs.

The Dreaded 404 on CPT Pages

In Resolve Intermittent ACF 404 Errors, CPT pages were randomly returning 404s. The root cause was a permalink flush issue.

Sorting and Pagination

Fix Sorting & Pagination of Custom Post Type β€” the archive page showed incorrect results because the main query conflicted with a custom WP_Query.

PHP Widget Integration

In Fix PHP Widget, a custom widget displaying CPT data was crashing because it wasn’t checking for empty results.

Best Practices

  • Always flush permalinks after registering CPTs
  • Use pre_get_posts for archive modifications
  • Add proper has_archive and rewrite rules
  • Test with the REST API to verify data structure

Need CPT help? Hire me on Upwork.

Similar Posts

12 Comments

  1. This is exactly what I needed! I was getting 404 errors on my custom post types after updating WordPress. Turns out my CPT registration was missing the rewrite flush. Your tip about flushing rewrite rules after CPT changes fixed it instantly. Thanks for the clear walkthrough!

    1. Glad it helped! Flushing rewrite rules is one of those things that trips up even experienced developers. If you ever run into pagination issues with CPTs, check the posts_per_page setting in your custom query as well.

  2. I’ve been struggling with ACF fields not showing up on my custom post type archive pages. The section about using get_field() with the post ID parameter was the missing piece for me. Really well-written guide.

    1. Thanks! Yes, ACF can be tricky on archive pages β€” always pass the post ID explicitly in the loop. Also worth noting that ACF fields won’t appear in REST API responses by default; you’ll need to enable ‘Show in REST’ on the field group.

  3. Quick question β€” does the rewrite flush trick work for CPTs registered via ACF’s built-in CPT feature (new in ACF 6.1)? Or does it only apply to CPTs registered with register_post_type() in PHP? I’m using ACF-registered CPTs and still getting occasional 404s.

    1. Great question! ACF 6.1+ CPTs handle rewrite rules automatically, but you may still need to manually flush after changing the slug. Go to Settings β†’ Permalinks and just click Save β€” that forces a flush. If 404s persist, check if you have a page with the same slug as your CPT archive β€” slug conflicts are a common cause.

Leave a Reply

Your email address will not be published. Required fields are marked *