custom post type - permalink = 404 (2 posts)

  1. espensl
    Posted 3 years ago #

    Hello I have a site, and I am trying to add a custom post type: 'product'
    I added that, and I set it up so that I can select a page as a parent. That works.

    But, permalinks do not work.

    I would like all custom post types "product" to be treated as regular pages. I want this structure:
    Where "electronics" is a regular page and "product-name" is custom post of the type "product"

    Anyone who can help me out with fixing the permalinks?

  2. espensl
    Posted 3 years ago #

    Here is the code that sets up the CPT and adds the "parent_id" field meta box.

    function create_post_type(){
    	$labels = array(
    		'name' => _x('Creditors','post type general name'),
    		'singular_name' => _x('Creditor', 'post type singular name'),
    		'add_new' => _x('Add New', 'creditor'),
    		'add_new_item' => __('Add New Creditor'),
    		'edit_item' => __('Edit Creditor'),
    		'new_item' => __('New Creditor'),
    		'all_items' => __('All Creditors'),
    		'view_item' => __('View Creditor'),
    		'menu_name' => __('Creditors'),
    		'parent_item_colon' => ''
    	$args = array(
    		'public' => true,
    		'hierarchical' => true,
    		'labels' => $labels,
    		'rewrite' => array('slug' => 'tilbydere'),
    		'has_archive' => true
    	register_post_type('creditor', $args);
    function creditor_custom_parent_setup(){
    	global $post;
    	$post_type_object = get_post_type_object($post->post_type);
    	if ( $post_type_object->hierarchical ) {
    	  $pages = wp_dropdown_pages(array(
          								'post_type' =>  'page',
          								'selected' => $post->post_parent,
          								'name' => 'parent_id',
          								'show_option_none' => __('(no parent)'),
          								'sort_column'=> 'menu_order, post_title',
          								'echo' => 0)
          if ( !empty($pages) ) {
            echo $pages;
            echo '<input type="hidden" name="parent_id_noncename" value="' . wp_create_nonce(__FILE__) . '" />';
          } // end empty pages check

Topic Closed

This topic has been closed to new replies.

About this Topic