Custom Post type category pages template and loop

You may alter the main query before the loop, but it’s crucial to reset the main query afterwards. Otherwise you’ll probably run into problems elsewhere. Disclaimer: Doing this is officially discouraged by WordPress here. However, in my experience it works perfectly to achieve the behaviour you want. Just don’t forget to add wp_reset_query(); after closing … Read more

Add a permalink variable onto custom post type URL after post name slug

Here’s a complete working example that adds a post type, with extra rule to capture an additional parameter: function wpd_post_type_and_rule() { register_post_type( ‘mycpt’, array( ‘labels’ => array( ‘name’ => __( ‘mycpt’ ), ), ‘public’ => true, ‘rewrite’ => array( ‘slug’ => ‘mycpt’ ), ) ); add_rewrite_tag( ‘%mycpt_var%’, ‘([^/]*)’ ); add_rewrite_rule( ‘^mycpt/([^/]*)/([^/]*)/?$’, ‘index.php?mycpt=$matches[1]&mycpt_var=$matches[2]’, ‘top’ ); } … Read more

Problems wp_insert_post and save_posts filter

you can check what post type is calling the ‘save_post’ action try: public function save() { global $post; if (!$post->post_type=”video”){ $my_child = array( ‘post_title’ => $this->_child_type, ‘post_content’ => “test content”, ‘post_status’ => ‘publish’, ‘post_type’ => “video”, ‘post_parent’=> 55 ); $nindex = wp_insert_post($my_child); } } add_action(‘save_post’, array(&$this, ‘save’));