WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] wp_query and multiple post types pagination problem (2 posts)

  1. tsiger
    Member
    Posted 4 years ago #

    2 days and a bit less hairy there it goes:

    We have the following query:

    global $paged;
    global $query_string;
    
    $arrParams = array(
     'post_type' => array('post',audio','video'),
     'paged' => $paged,
     'posts_per_page' => 5,
     'caller_get_posts'=> 1
    );
    
    $arrQuery = array();
    parse_str($query_string,$arrQuery);
    
    $temp = $wp_query;
    $wp_query = null;
    $wp_query = new WP_Query();
    $wp_query->query(array_merge($arrQuery, $arrParams));
    
    while ($wp_query->have_posts()) : $wp_query->the_post();
    
    // i display stuff
    
    ci_pagination(); // just including the next/prev links
    $wp_query = null; $wp_query = $temp;

    Now, i have like 3 posts, 1 audio and 2 videos all of them in the same category (i have registered the post types audio and video with the ability to have categories).

    The weird thing: IF the Blog pages show at most setting in the Reading Settings is smaller than my post_per_page number everything works smoothly. I move from page to page (prev/next) smoothly without any problems.

    If the Blog pages show at most setting is equal or higher than my post_per_page, when u try to get to the last page of the results you get an 404. 0_o

    The code above is located in category.php ( i have tried archive.php as well with no luck).

    Any ideas?

  2. tsiger
    Member
    Posted 4 years ago #

    Solved.

    the prolbem was that we were registering the post type with the following args:

    $args = array(
    	'labels' => $labels,
    	'singular_label' => __('Audio'),
    	'public' => true,
    	'show_ui' => true,
    	'capability_type' => 'post',
    	'hierarchical' => false,
    	'rewrite' => true,
    	'menu_position' => 5,
    	'supports' => array('title', 'editor', 'comments', 'revisions')
    	'taxonomies' => array('category', 'post_tag', 'audionomy')
    	);

    and we could see the taxonomies just fine under the custom post type.
    Well taxonomies => blah blah won't cut it.

    You need to seperately register them

    register_taxonomy_for_object_type('category', 'audio');
    register_taxonomy_for_object_type('post_tag', 'audio');

Topic Closed

This topic has been closed to new replies.

About this Topic