• Hi!
    I’ve got totally stuck.

    Ok, so I’ve made a custom post types and sat up it’s own taxonomy. So far so good. But now, when I enter it’s categories’ archive page, I just get a 404 telling me that page doesn’t exist.

    Here’s the code I’ve added for the taxonomy and custom post types:

    add_action( 'init', 'create_faq_taxonomies', 0 );
    
    // create two taxonomies, genres and writers for the post type "book"
    function create_faq_taxonomies() {
    	// Add new taxonomy, make it hierarchical (like categories)
    	$labels = array(
    		'name'              => _x( 'Kategori', 'taxonomy general name' ),
    		'singular_name'     => _x( 'Kategori', 'taxonomy singular name' ),
    		'search_items'      => __( 'Sök kategori' ),
    		'all_items'         => __( 'Alla kategorier' ),
    		'parent_item'       => __( 'Förälder' ),
    		'parent_item_colon' => __( 'Förälder:' ),
    		'edit_item'         => __( 'Redigera' ),
    		'update_item'       => __( 'Uppdatera kategori' ),
    		'add_new_item'      => __( 'Lägg till kategori' ),
    		'new_item_name'     => __( 'Nytt namn' ),
    		'menu_name'         => __( 'Kategori ),
    	);
    
    	$args = array(
    		'hierarchical'      => true,
    		'labels'            => $labels,
    		'show_ui'           => true,
    		'show_admin_column' => true,
    		'query_var'         => true,
    		'rewrite'           => array( 'slug' => 'faq' ),
    	);
    
    	register_taxonomy( 'faq', array( 'x_faq' ), $args );

    ///////////////////////////////////////////////////

    function create_post_types() {
    
    		register_post_type(
    			'x_faq',
    			array(
    				'labels' => array(
    					'name' 			=> __( 'FAQ', 'x_faq' ),
    					'singular_name' => __( 'FAQ', 'x_faq' ),
    					'add_new'		=> __( 'Skapa ny', 'x_faq' ),
    					'add_new_item'	=> __( 'Skapa ny FAQ', 'x_faq' ),
    					'edit'			=> __( 'Redigera', 'x_faq' ),
    					'edit_item'		=> __( 'Redigera FAQ', 'x_faq' ),
    					'new_item'		=> __( 'Ny FAQ', 'x_faq' ),
    					'view'			=> __( 'Visa FAQ', 'x_faq' ),
    					'view_item'		=> __( 'Visa FAQ', 'x_faq' ),
    					'search_items'	=> __( 'Sök FAQ', 'x_faq' ),
    					'not_found'		=> __( 'Hittade ingen FAQ', 'x_faq' ),
    					'not_found_in_trash' => __( 'Hittade ingen FAQ i papperskorgen', 'x_faq' ),
    					'parent'		=> __( 'Förälder', 'x_faq' ),
    				),
    				'description' 		=> __( 'Skapa en FAQ.', 'x_faq' ),
    				'public'			=> true,
    				'show_ui' 			=> true,
    				'show_in_menu' 			=> true,
    				'publicly_queryable'	=> true,
    				'exclude_from_search' 	=> true,
    				'menu_position' 		=> 11,
    				'hierarchical'		=> true,
    				'query_var'			=> true,
    				'supports' 	=> array (
    					'title', //Text input field to create a post title.
    					'editor',
    					'thumbnail'
    				)
    			)
    		);
    	}
    }
    
    add_action( 'init', 'create_post_types' ); // register post type

    Is there anybody out there who knows why this happens? Happy if someone please could help me out here.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You may get a (quicker) response in one of the more Advanced forums. This forum is more for basic WP questions.

    Thread Starter Corneliatt

    (@corneliatt)

    Hi and thanks for your answer. Can’t move this, so I guess I have to stay here 😉
    I got it to work tho.. but with one problem solved, I found a new one… And this one is really basic, so I think it fits here 😉

    I have got a query that looks like this:

    $new_query = new WP_Query(array('faq' => 'question', 'post_type' => 'question_faq', 'orderby' => 'rand', 'showposts' => '1'));

    This works perfectly. But it doesn’t work if I change ‘question’ to the variable $title like this:

    $title = the_title();
    echo $title;
    
    $new_query = new WP_Query(array('faq' => $title, 'post_type' => 'question_faq', 'orderby' => 'rand', 'showposts' => '1'));

    In the echo just before the query the $title is echoed just perfectly, but as soon as it gets into the query it somehow looses its value.

    Does anyone know why is this?

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Custom post types taxonomy’ is closed to new replies.