WordPress custom post type rewrite rule matches all pages returning 404

I managed to find a solution thanks to Milo‘s previous answers on other related questions. I found this particular post Remove base slug in CPT & CT, use CT in permalink to be extremely helpful. My initial CPT with grandparent relationship rewrite remains the same: function cpt_child(){ $args = array( //code ‘rewrite’ => array( ‘slug’ … Read more

Getting a 404 on single custom post type page when using rewrite on a custom taxonomy

Add priority with at least 1 to your add actions: add_action( ‘init’, ‘add_training_post_type’, 1 ); add_action( ‘init’, ‘create_training_taxonomies’, 1 ); Currently your issue is that your post type and taxonomy rewrite slugs are identical, so the URL base would be the same and it confuses WP. Fortunately there is easy solution, just add this code … Read more

issue with custom post type feed

Note that $query->is_feed() is true for both feeds, so you’re changing both of them with the pre_get_posts hook. I skimmed quickly through the WP_Query object for those feeds and if you want to combine these two post types, only for the main feed example.tld/feed/, you could try: add_filter( ‘pre_get_posts’, function( \WP_Query $q ) { if … Read more

Custom post URLs

You can try the slug agument under rewrite parameter of register_post_type() function: add_action( ‘init’, ‘egister_hosts_post_type’ ); function register_hosts_post_type() { $args = array( // …. ‘rewrite’ => array( ‘slug’ => ‘programs/hosts’ ), ); register_post_type( ‘hosts’, $args ); } As this affect the rewrite rules, you should flush them on activation/deactivation of the plugin: add_action( ‘init’, ‘cyb_register_hosts_post_type’ … Read more

Remove parent slugs from URLs on three customs posts types

Simply add more conditions to the if( ‘CPT1’ != $post->post_type ) construct. Separate and describe the relationship between condition expressions using logical operators: function wpse_222797a_flatten_hierarchies( $post_link, $post ) { // IF( ‘CPT1’ IS NOT the post_type // AND ‘CPT2’ IS NOT the post_type // AND ‘CPT3’ IS NOT the post_type ) // THEN exit the … Read more