Not really getting the post types
-
Trying to get some understanding regarding the post types.
In this case I’m working on my own theme and in index.php i have this code:global $post; dx($post); dx(get_post_type());(the dx function is just a small function that makes this:
function dx($a) { echo '<pre>'; var_dump($a); echo '</pre>';})Now, to the problem. In a plugin i register e new post type, let’s say ‘cars’. something like this:
add_action( 'init', 'create_cars_post_type' ); function create_cars_post_type() { register_post_type( 'cars',array( 'labels' => array( 'name' => __( 'Cars' ), 'singular_name' => __( 'Car' ), 'slug' => __('cars'), 'view_item' => __('show cars') ), 'public' => true, 'has_archive' => true, 'hierarchical' => false, 'rewrite' => array('slug'=>'cars') ) ); }The question regards the rewrite part. Lets say I create a nice car, let’s call it “volvo”. Now the url is nice and is [mydomain]/cars/volvo.
However, my code from index.php gives me this:null boolean falseOk, it’s no post and the post type can’t be found.
If i set the rewrite tofalsemy index.php outputs the post object and my post type -> but the url is now [mydomain]?cars=volvo and that sucks. 🙂What am i missing? How can I have nice URL:s and make WP accept it as a post?
The topic ‘Not really getting the post types’ is closed to new replies.