• Resolved briangelhaus

    (@briangelhaus)


    I have a custom post type called “custom_news”.
    It has this arguement:
    'rewrite' => array('with_front' => false,'slug' => 'news'),
    So my news post URLs are site.com/news/title-of-post

    I created a new page called “news” so it’s at site.com/news
    The problem is pagination no longer works at site.com/news/page/2
    It doesnt work because it’s trying to find an actual news post called “page” but that doesnt exist.

    How can I make the pagination work while also keeping the news post slug “news”?

    $pageNumber = ($paged) ? $paged : 1;
    $args = array(
    	'post_type' => 'custom_news',
    	'posts_per_page' => 10,
    	'post_status' => 'publish',
    	'paged' => $pageNumber,
    );
    $query = new WP_Query($args);
    
    • This topic was modified 7 years, 2 months ago by briangelhaus.
    • This topic was modified 7 years, 2 months ago by briangelhaus.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Hi briangelhaus

    Is there a reason you don’t set has_archive to true when registering the post type? Then you don’t even need to create a page for the archive.

    https://developer.www.ads-software.com/reference/functions/register_post_type/#parameters

    Thread Starter briangelhaus

    (@briangelhaus)

    That wasn’t working for me at first, but now it is. Thanks!

    One reason I don’t like this way is that there is no “edit page” at the top. Harder for clients to edit any extra fields or body copy besides the posts showing on this page.

    • This reply was modified 7 years, 2 months ago by briangelhaus.
    Moderator bcworkz

    (@bcworkz)

    There is no “edit custom_news” in the admin bar on archive pages because archives have multiple posts. Which post would we be editing if such a link was present? Many themes output an edit link with each post listing when the logged in user has edit posts capability. If your theme does not output such links, they can be added. The best way to do so depends on the theme.

    We need to do everything possible to make it easier for clients, most are easily confused. But we cannot read their minds if offering a single link to edit any number of possible posts ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Pagination not working with custom post type’ is closed to new replies.