Pagination with custom post type (8 posts)

  1. tina_tech
    Posted 2 years ago #

    So, I have read endless "solutions" and have spent hours troubleshooting this but still nothing so I'm hoping posting here (my first time posting) will give me the solution I so desperatly need!

    My problem: I have a post type called "Links" which displays lists of urls from three different taxonomies. There are three rows for each taxonomy and each one is supposed to display 3 urls and a link to see previous urls. The previous link shows a 404, and I can't seem to fix it no matter what I do.

    My code:

    $paged = ( get_query_var( 'paged' ) ) ? get_query_var('paged') : 1;
    $args = array( 'post_type' => 'lenker', 'lenketyper' => 'vitenskapelige-publikasjoner', 'posts_per_page' => 2, 'paged' => $paged );
    	$loop = new WP_Query( $args );
    	while ( $loop->have_posts() ) : $loop->the_post(); {
    	     $url_excerpt = get_the_excerpt();
    	     if ( $url_excerpt != '' ) { ?>
                <span class="bullet"></span><a href="<?php echo $url_excerpt; ?>"><?php the_title(); ?> </a>
                      <?php echo '</br>';
    endwhile; ?>
             <?php previous_posts_link('« Forrige', $loop->max_num_pages);   ?>
             <?php next_posts_link('Neste »', $loop->max_num_pages); ?>

    I have added 'rewrite' => array( 'slug' => 'lenke' ), to my post type and gone to "Settings" > "Permalinks" And clicked "Save Changes" (I have also reset the permalinks).

    Hope the question wasn't to badly written!

    Link to the site: http://tinahaaskjold.com/ntnu/lenke/
    the first column is the one the code above is used on.

  2. kevin heath
    Posted 2 years ago #

    You seem to be having an issue with your permalinks somewhere as when I click on any of the links in that dirst box there is an addition ntnu

    eg your 404 page is shown that the link is going to

    Check your permalinks settings again and how have you set up your custom post type?


  3. tina_tech
    Posted 2 years ago #

    This is from functions.php:

    add_action( 'init', 'register_cpt_lenker' );
    function register_cpt_lenker() {
        $labels = array(
            'name' => _x( 'Lenker', 'lenker' ),
            'singular_name' => _x( 'Lenke', 'lenker' ),
            'add_new' => _x( 'Legg til ny', 'lenker' ),
            'add_new_item' => _x( 'Legg til ny lenke', 'lenker' ),
            'edit_item' => _x( 'Rediger lenke', 'lenker' ),
            'new_item' => _x( 'Ny lenke', 'lenker' ),
            'view_item' => _x( 'Se lenke', 'lenker' ),
            'search_items' => _x( 'Søk lenker', 'lenker' ),
            'not_found' => _x( 'Ingen lenker funnet', 'lenker' ),
            'not_found_in_trash' => _x( 'Ingen lenker funnet i papirkurven', 'lenker' ),
            'parent_item_colon' => _x( 'Parent Lenke:', 'lenker' ),
            'menu_name' => _x( 'Lenker', 'lenker' ),
        $args = array(
            'labels' => $labels,
            'hierarchical' => false,
            'description' => 'Alle interne og eksterne lenker til ulike rapporter/publikasjoner/ressurser.',
            'supports' => array( 'title', 'excerpt' ),
            'taxonomies' => array( 'category', 'lenketyper' ),
            'public' => true,
            'show_ui' => true,
            'show_in_menu' => true,
            'menu_position' => 20,
            'show_in_nav_menus' => true,
            'publicly_queryable' => true,
            'exclude_from_search' => false,
            'has_archive' => true,
            'query_var' => true,
            'can_export' => true,
            'rewrite' => array( 'slug' => 'lenke' ),
            'capability_type' => 'post'
        register_post_type( 'lenker', $args );

    I have tried different permalinkssetting, but the result is the same... I have tried all the suggestions in this thread but the result is the same.

  4. kevin heath
    Posted 2 years ago #


    Have you tried to test it without permakinks switched on?


  5. kevin heath
    Posted 2 years ago #

    you could also try using the rewrite option:

    'rewrite' => array( 'slug' => 'lenke', 'with_front' => false ),

    to see if that removes the additional ntnu.


  6. tina_tech
    Posted 2 years ago #

    I tried switching to the standard permalink option, but what is the url of the post type then?

    I have now added 'rewrite' => array( 'slug' => 'lenke', 'with_front' => false ), but as you can see it's still the same...

  7. kevin heath
    Posted 2 years ago #


    you select default from your permalink settings and your link address with look something like


    The p=123 related to the post id and you can get that from going into your edit post page and the post id will showe in your browser url bar.

    personally I'm pretty sure this is a permalinks issue rather than a pagination one.


  8. tina_tech
    Posted 2 years ago #

    There is no post id, because as you can see it's an archive page (which lists out different post who all have individual post ids)...

Topic Closed

This topic has been closed to new replies.

About this Topic