• Hi, i have a serious problem with custom post type single. I have created custom post type named ‘projects’. At this time, i have seen nothing wrong with my codes in functions. Everything works fine, but single-projects.php doesn’t. It appears blank page everytime i enter a project, and i don’t know why. I have googled many times, and i can make sure that it is not permalink problem (many others got this).
    Here is registering codes in functions:

    function create_post_type() {
      register_post_type( 'projects',
        array(
          'labels' => array(
            'name' => __( 'Projects' ),
            'singular_name' => __( 'Project' ),
          ),
          'public' => true,
          'has_archive' => true,
          'show_ui' => true,
          'menu_icon'   => 'dashicons-portfolio',
          'rewrite' => true,
          'supports' => array('title', 'custom-fields', 'editor', 'revisions', 'thumbnail', 'author')
        )
      );
      flush_rewrite_rules();
    }

    And obviously, single-projects.php is copied from single.php.
    I hope anyone could help me!
    Thank you very much!

Viewing 9 replies - 1 through 9 (of 9 total)
  • Is the page completely blank or just part blank. If it is complexity blank, there is a good chance that there is a syntax error.

    Do you see a title in the browser tab?

    Thread Starter sagitt000

    (@sagitt000)

    It is completely blank, no title, just only url.
    Any clue for a syntax error, please?

    You could send a link to pastebin containing your code your are using for the single-projects.php.

    Thread Starter sagitt000

    (@sagitt000)

    https://pastebin.com/apxU4fUS
    It has the exactly same code with single.php. It should work.

    I am seeing syntax errors right off the get go.

    if ( is_singular('projects') )
    			the_content();
    		else (
    		// Start the loop.
    		while ( have_posts() ) : the_post();

    Looks like you are missing a bracket and use parenthesis instead of brackets. You also do not need to do a is_single check since the file is named single-projects.php.

    Hey edit my code and change it according to your needs
    Here it is complete example of custom post and save the post.

    <?php
    /******************************************************Custom Recipe Post Type************************************************************************/
    
    add_action( 'init', 'register_cpt_Recipe' );
    function register_cpt_Recipe() {
    
        $labels = array(
            'name' => _x( 'All Recipe', 'Recipe' ),
            'singular_name' => _x( 'All Recipe', 'Recipe' ),
            'add_new' => _x( 'Add New Recipe', 'Recipe' ),
            'add_new_item' => _x( 'Add New Recipe', 'Recipe' ),
            'edit_item' => _x( 'Edit Recipe', 'Recipe' ),
            'new_item' => _x( 'New Recipe', 'Recipe' ),
            'view_item' => _x( 'View Recipe', 'Recipe' ),
            'search_items' => _x( 'Search Recipe', 'Recipe' ),
            'not_found' => _x( 'No Recipe found', 'Recipe' ),
            'not_found_in_trash' => _x( 'No Recipe found in Trash', 'Recipe' ),
            'parent_item_colon' => _x( 'Parent Recipe:', 'Recipe' ),
            'menu_name' => _x( 'All Recipe', 'Recipe' ),
        );
    
        $args = array(
            'labels' => $labels,
            'hierarchical' => true,
    
            'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'page-attributes' ),
            'taxonomies' => array( 'category', 'post_tag', 'page-category' ),
            'public' => true,
            'show_ui' => true,
            'show_in_menu' => true,
    
            'show_in_nav_menus' => true,
            'publicly_queryable' => true,
            'exclude_from_search' => false,
            'has_archive' => true,
            'query_var' => true,
            'can_export' => true,
            'rewrite' => true,
            'capability_type' => 'post',
    		'taxonomies' => array('recipe_type')
        );
    
        register_post_type( 'Recipe', $args );
    
    }
    
    function add_recipe_type_taxonomies() {
    
    	register_taxonomy('recipe_type', 'review', array(
    		// Hierarchical taxonomy (like categories)
    		'hierarchical' => true,
    		// This array of options controls the labels displayed in the WordPress Admin UI
    		'labels' => array(
    			'name' => _x( 'Recipe Category', 'taxonomy general name' ),
    			'singular_name' => _x( 'Recipe-Category', 'taxonomy singular name' ),
    			'search_items' =>  __( 'Search Recipe-Categories' ),
    			'all_items' => __( 'All Recipe-Categories' ),
    			'parent_item' => __( 'Parent Recipe-Category' ),
    			'parent_item_colon' => __( 'Parent Recipe-Category:' ),
    			'edit_item' => __( 'Edit Recipe-Category' ),
    			'update_item' => __( 'Update Recipe-Category' ),
    			'add_new_item' => __( 'Add New Recipe-Category' ),
    			'new_item_name' => __( 'New Recipe-Category Name' ),
    			'menu_name' => __( 'Categories' ),
    		),
    
    		// Control the slugs used for this taxonomy
    		'rewrite' => array(
    			'slug' => 'recipe_type', // This controls the base slug that will display before each term
    			'with_front' => false, // Don't display the category base before "/locations/"
    			'hierarchical' => true // This will allow URL's like "/locations/boston/cambridge/"
    		),
    	));
    }
    add_action( 'init', 'add_recipe_type_taxonomies', 0 );

    @ravikas Thanks for the input but the OP is not having issues creating the CPT, they are having issues displaying them. Also, next time please wrap you code in the code ticks. It makes the forum easier to read.

    @sagitt000 The code you provided is not from the original single.php file. There is improper code added. Remove the code that has been added and you should be good to go.

    @justin Greer ok

    Thread Starter sagitt000

    (@sagitt000)

    Oh sorry for being late, mates.

    @justin: You are right about is_singlular, I removed it, but it’s still blank. Besides, i think those codes can’t make it blank, it is just not necessary.

    @ravikas: Basically, i have done the same thing to you for registering CPT and etc. And Justin also got the point, it is about displaying. Others work fine as they should be.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Custom post type single’ is closed to new replies.