• Resolved jplus2

    (@jplus2)


    Hello,

    I am having a problem with paginating custom post type

    I have a custom post type named “news”
    and I have a file, an archive file, name “archive-news.php”
    My permalink is set to Post Name

    here is the link: http://davaohotelelena.com/dev/news/

    when you to that link, it displays all the news, the pagination below seemed to work find, but when you go to the subsequent page, it will use the index.php file as the template, instead of the archive-news.php

    I have tried to change the permalink and set it back to post name again, still didn’t work

    Below is my code for registering the custom post type

    function he_custom_post_types() {
    
    // News
    	$labels = array(
    		'name'                => _x( 'Latest News', 'Latest News', 'he_framework' ),
    		'singular_name'       => _x( 'News', 'News', 'he_framework' ),
    		'menu_name'           => __( 'Latest News', 'he_framework' ),
    		'parent_item_colon'   => __( 'Parent News:', 'he_framework' ),
    		'all_items'           => __( 'All News', 'he_framework' ),
    		'view_item'           => __( 'View News', 'he_framework' ),
    		'add_new_item'        => __( 'Add New News', 'he_framework' ),
    		'add_new'             => __( 'New News', 'he_framework' ),
    		'edit_item'           => __( 'Edit News', 'he_framework' ),
    		'update_item'         => __( 'Update News', 'he_framework' ),
    		'search_items'        => __( 'Search News', 'he_framework' ),
    		'not_found'           => __( 'No News found', 'he_framework' ),
    		'not_found_in_trash'  => __( 'No News found in Trash', 'he_framework' ),
    	);
    
    	$args = array(
    		'label'               => __( 'Latest News', 'he_framework' ),
    		'description'         => __( 'Latest News Information Pages', 'he_framework' ),
    		'labels'              => $labels,
    		'supports'            => array('title','editor','author','excerpt','comments','revisions','thumbnail'),
    		'taxonomies'          => array(),
    		'hierarchical'        => true,
    		'public'              => true,
    		'show_ui'             => true,
    		'show_in_menu'        => true,
    		'show_in_nav_menus'   => false,
    		'show_in_admin_bar'   => true,
    		'menu_position'       => 21,
    		'menu_icon'           => '',
    		'can_export'          => true,
    		'has_archive'         => true,
    		'exclude_from_search' => false,
    		'publicly_queryable'  => true,
    		'capability_type'     => 'page'
    	);
    
    	register_post_type('news',$args);
    
    }
    
    // Hook into the 'init' action
    add_action( 'init', 'he_custom_post_types', 0 );

    Thank you in advance for the help

    God Speed

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter jplus2

    (@jplus2)

    Darn!!!

    I figured it out, it turns out that all my codes are good, no problem.
    The problem is the setting on the wordpress admin conflicts with the post per page I set on my code

    on my archive-news.php, I set post_per_page on my WP_Query arg as 5, now on my admin settings/reading it is set to 10, when I set it to 5, it worked now!

    IMHO, since it is set to 10, then page 2 basically doesn’t exist, coz I only have 7 pages, so wordpress taught he already displayed all items, so page 2 doesn’t exist, since I do not have a 404.php yet, it fallsback to index.php

    this is not an obvious issue since on my listing, it only shows 5 items, not 7, so it is very difficult to detect, Darn!!! talk me half a day to debug it

    Hope this helps to anybody who also had this issue

    Hi
    I have same prb in custom post pagination.
    Pagination is working in default permalink but not work in postname permalink.
    My code is below

    Template Page:

    <?php
    /*
    	Template Name: News
    */
    get_header();
    wp_reset_query();
    	$temp=$wp_query;
    	$wp_query=NULL;
    	$wp_query=new WP_Query();
    	$wp_query->query('post_type=news&posts_per_page=1&order=DESC&paged='.$paged);
        if ($wp_query->have_posts()) :while ($wp_query->have_posts()) : $wp_query->the_post();
    
    /* template contents */
    
    endwhile; ?>
    	<div class="paginate">
    		<div id="previous" style="float:left;"><?php previous_posts_link("&laquo; Previous"); ?></div>
    		<div id="next" style="float:right;"><?php next_posts_link("Next &raquo;"); ?></div>
    	</div>
    	<?php endif; ?>

    Function

    add_action( 'init', 'create_my_post_types' );
    function create_my_post_types()
    {
    register_post_type( 'news',
    		array(
    			'labels' => array(
    				'name' => __( 'News' ),
    				'singular_name' => __( 'News' ),
    				'add_new_item' => __( 'Add New News' ),
    				'edit_item' => __( 'Edit News' )
    			),
    			'public' => true,
    			'show_in_nav_menus' => false,
    		)
    	);
    }

    This produce 404 error in news/page/2

    Pls help me.

    Thanks in advance

    Ya its works.
    I made a little mistake in my page.
    When I was correct it works beautifully. The prb is my page name and custom post name was same. I changed the name it works perfectly

    antgonzales

    (@antgonzales)

    @jplus2

    on my archive-news.php, I set post_per_page on my WP_Query arg as 5, now on my admin settings/reading it is set to 10, when I set it to 5, it worked now!

    Best response ever. Thank you for finding that out. I was going crazy looking at the archive page and my functions settings. Such a stupid little error.

    shinuskn

    (@shinuskn)

    Actually me too faced the same problem of custom post type with template page seems 404 error. The problem was my page name and custom post name was same. I rewrite the custom post type slug while registering the post type, it works perfectly. And don’t forget to update your permalink after rewrite.

    ‘rewrite’ => array( ‘slug’ => ‘book’ )

    Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Custom Post Type Pagination (Not Working)’ is closed to new replies.