php - Wordpress custom post type categories -


hey. using custom post type in wordpress. register custom post type this:

        register_post_type("lifestream", array(             'label' => 'lifestream',             'public' => true,             'hierarchical' => true,             'menu_position' => 5,             'supports' => array('title','editor','author','thumbnail','comments','custom-fields'),             'taxonomies' => array('category','post_tag'),             'query_var' => true,             'publicly_queryable' => true,             'exclude_from_search' => false,             'caller_get_posts' => 1          ));         register_taxonomy_for_object_type('category', 'lifestream');         register_taxonomy_for_object_type('post_tag', 'lifestream'); 

in theme (the loop template) combine posts , custom post type, using query_posts() these parameters:

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array(     'post_type' => array('post', 'lifestream'),     'paged' => $paged,     'cat' => $wp_query->get('cat'),     'tag' => $wp_query->get('tag'),     'year' => $wp_query->get('year'),     'monthnum' => $wp_query->get('monthnum'),     'post_status' => 'publish',     'showposts' => 3 ); query_posts($args);    # loop      while ( have_posts() ) : the_post();  # markup endwhile;   if($wp_query->max_num_pages > 1):  # next_posts_link / previous_posts_link endif;  wp_reset_query();    

this working far. but, got problems category , tags pages. if call frontpage fine , can paginate through pages getting correct results.

and, if call paged url, e.g. /category/mycat/page/2 404 thrown. there definitly should posts. no matter if there custom type posts or normale posts in category. suppose parameters query_posts() aren´t correct, don´t know ...

it seems $wp_query->max_num_pages has wrong value. why? register taxonomies (i use categories , tags custom post types) correctly?

do have idea do? lot!

i have encountered exact same problem , couldn't find solution anywhere! internets full of resources topic none provided correct answer issue.

here's correct answer searching. put below code in functions.php in theme's root directory.

function init_category($request) {     $vars = $request->query_vars;     if (is_category() && !is_category('blog') && !array_key_exists('post_type', $vars)) :         $vars = array_merge(             $vars,             array('post_type' => 'any')         );         $request->query_vars = $vars;     endif;     return $request; } add_filter('pre_get_posts', 'init_category'); 

all credits go mike posted on wordpress.com. cheers!


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -