Wordpress Custom Email Categories

Hey. I am using a custom post type in wordpress. I will register this custom post type as follows:

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 the subject (loop pattern), I like to combine posts and my custom post type, because I use query_posts () with 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); # the 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(); 

It still works. But I have problems with category and tag pages. If I call the main page, everything is in order, and I can break the pages into pages, getting the correct results.

And, if I call a paged URL, for example. / category / mycat / page / 2 a 404. But there definitely should be posts. Regardless of whether there are personalized posts or normal posts in the category. I believe my parameters for query_posts () are not correct, but they don’t know ...

$ Wp_query-> max_num_pages seems to have the wrong value. But why? Am I registering taxonomies correctly (like using categories and tags for my custom post types)?

Do you have an idea what to do? Many thanks!

+6
php wordpress themes categories custom-post-type
source share
3 answers

I just ran into the same problem and couldn't find a solution anywhere! The Internet is full of resources on the topic, but no one has given the correct answer to the question.

Here is the right answer for anyone looking. Put the code below in functions.php in the root directory of the theme.

 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 loans are transferred to Mike , who posted this on Wordpress. com Hooray!

+2
source share

Make sure you add the following:

 'paged' => get_query_var('paged') 

to your $ args and it should accept the paging in order.

More here

0
source share

In archive.php, try using the following:

 query_posts( array( 'post_type' => 'lifestream', 'posts_per_page' => 6, 'orderby' => 'menu_order', 'orderby' => 'date', 'order' => 'ASC', 'paged' => '' . get_query_var('paged') )); if ( have_posts() ) : while ( have_posts() ) : the_post(); endwhile; else: endif; 

For the following and previous page links, I use:

 next_posts_link('Older Entries', $wp_query->max_num_pages); previous_posts_link('Newer Entries', $wp_query->max_num_pages); 
0
source share

All Articles