Support » Developing with WordPress » Custom Post Type pgae blank after rewrite flush

  • Resolved StephenEquus

    (@stephenequus)


    I’m creating a custom post type plugin – this isn’t my first. So far I think I’ve done everything correct, but when I check the page after I create it I get a 404 page. I did some research into what might be causing this. Many articles say to do a rewrite flush in functions.php – which I did. After I did this the 404 page became a blank, white page. I tried the flush in Settings -> Permalinks next but the page is still blank white. If I change the ‘rewrite’ -> ‘slug’ in my plugin then I get back to the 404 page problem.

    Any ideas? Here is the custom post type code:

    <?php
    
    /**
    * Plugin Name: Status Events
    * Description: Adds a custom post type page for status events
    * Author: Stephen Jensen
    * Version: 1.0.0
    * License: GPL v2 or later
    * License Address: http://www.gnu.org/licenses/gpl-2.0.txt
    **/
    
    defined( 'ABSPATH' ) or die( 'You Shall Not Pass!' );
    
    	function rsevent_create_post_type(){
    		$labels = array(
    			'name'               => 'Status Event',
    			'singular_name'      => 'Status Event',
    			'add_new'            => 'Add New',
    			'add_new_item'       => 'Add New Status Event',
    			'edit_item'          => 'Edit Status Event',
    			'new_item'           => 'New Status Event',
    			'view_item'          => 'View Status Event',
    			'search_items'       => 'Search Status Event',
    			'not_found'          => 'No Status Event Found',
    			'not_found_in_trash' => 'No Status Event Found in Trash'
    		);
    		$args = array(
    			'labels'             => $labels,
    			'has_archive'        => false, // these will be used in pages
    			'public'             => true,
    			'hierarchical'       => true, // behave like a page
    			'show_in_menu'       => 'options-general.php', // place plugin menu in Settings menu
    			'rewrite'            => array(
    				'with_front'       => false, // false removes permalink /blog/ structure
    				'slug'             => 'status-event'
    			),
    			// 'menu_icon'          => 'dashicons-warning',
    			'supports'           => array( // features
    				'title',
    				'author',
    				'page-attributes'
    			)
    		);
    		register_post_type('rsevent', $args);
    	}
    	add_action('init', 'rsevent_create_post_type');
    
    ?>

    the single page is called single-rsevent.php

Viewing 4 replies - 1 through 4 (of 4 total)
  • When I removed single-rsevent.php from the server it defaulted to single.php so I think I named it correctly. I think there might be something in the single.php that is preventing the single-rsevent.php from being used when it is a custom post type. I wonder what could be doing that?

    Hi @stephenequus,

    If you can just deactivate the plugin and add the following code

    $set = get_option( 'cpt_rsevent_flushed_rewrite_rules' );
    if ( $set !== 'yes' ){
    	flush_rewrite_rules( false );
    	update_option( 'cpt_rsevent_flushed_rewrite_rules', 'yes' );
    }

    just after

    register_post_type('rsevent', $args);

    and then re-activate the plugin, the rewrite rules would be flushed by code and single-rsevent.php would work fine.

    [ Signature moderated. ]

    I finally got the page to show up. Now I need to figure out why my Advanced Custom Field content is not showing up on the page. Thanks for the help Adarsh.

    Ha!. Forgot to wrap everything in:

    <?php if ( have_posts() ) :
    while ( have_posts() ) : the_post();
    if( have_rows('modules') ):
    while ( have_rows('modules') ) : the_row();
    
    ... my acf content ...
    
    endwhile;
    endif;
    endwhile;
    endif; ?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom Post Type pgae blank after rewrite flush’ is closed to new replies.