• Resolved selcuk33

    (@selcuk33)


    Hi,

    I have 3 post type ; “post”, “dersler”, “ipuclari”. I want to show all of them in the index page. I try this with this code :

    <?php
    				$pagedd = (get_query_var('paged')) ? get_query_var('paged') : 1;
    				$wp_query = new WP_Query(array('paged'=>$pagedd, 'post_type'=>array('post','dersler','ipuclari')));
    
    				if(have_posts()): while(have_posts()): the_post();
    			?>

    And my pagination code is :

    function pagination(){
    	global $paged,$wp_query;
    	if(empty($paged)) $paged = 1;
    
    	$pages 		= $wp_query->max_num_pages;
    	$is_start 	= (1 == $paged) ? true : false;
    	$is_end 	= ($pages == $paged) ? true : false;
    	$for_start	= ($paged-2 < 1) ? 1 : $paged-2;
    	$for_end	= ($paged+2 > $pages) ? $pages : $paged+2;
    
    	echo '<ul class="pageNumbers">';
    		echo ($is_start) ? "" : "<li><a href='".get_pagenum_link(1)."'>? ?lk Sayfa</a></li>";
    		echo ($paged > 1) ? "<li><a href='".get_pagenum_link($paged-1)."'>?</a></li>" : "";
    		for($i=$for_start; $i<=$for_end; $i++){
    			echo ($paged == $i) ? "<li class='active'><a href='javascript:void;'>$i</a></li>" : "<li><a href='".get_pagenum_link($i)."'>$i</a></li>";
    		}
    		echo ($paged < $pages) ? "<li><a href='".get_pagenum_link($paged+1)."'>?</a></li>" : "";
    		echo ($is_end) ? "" : "<li><a href='".get_pagenum_link($pages)."'>Son Sayfa ?</a></li>";
    	echo '</ul>';
    	echo "<span class='pageInfo'>$pages sayfada $paged. sayfadas?n?z</span>";
    }

    Pagination is work greatly. But if i click 5 site goes mysite.com/page/5/ but wordpress redirect 404 error page.

    Note: if i write paged manually like ;

    $wp_query = new WP_Query(array('paged'=>5, 'post_type'=>array('post','dersler','ipuclari')));

    this perfectly show page 5. but mysite.com/page/5 doesn’t work please somebody help me :/

Viewing 3 replies - 1 through 3 (of 3 total)
  • hi, you could try this

    function my_custom( $query ) {
            if(is_front_page()){
                 $query->query_vars['post_type'] = array( 'post', 'dersler', 'ipuclari');
            }
    }
    add_action('pre_get_posts', 'my_custom');

    You already have WP_Query running for posts only when you load the pages.

    When you hit page 5, you don’t have any more “posts” and therefore you got 404 error page.

    To fix it, you must hook into fx. the pre_get_posts action.

    Hope this helps.

    Thread Starter selcuk33

    (@selcuk33)

    yeap its work thanks ?? my problem is resolved but i want to learn something… Why WP_Query running for only post ? I say to wordpress “hey, i have 3 custom post types list all of them” but wordpress only list posts why ?

    I guess it’s legacy thing to let the main loop use only “posts” and of course “posts” are the default post_type.

    It would be nice if one could let WordPress know, via cpt registration, what post_types to use in the main loop.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Pagination with Custom Post Type is Broken’ is closed to new replies.