• 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.

Viewing 7 replies - 1 through 7 (of 7 total)
  • 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
    /ntnu/ntnu/lenke/page/2/

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

    thanks
    Kevin

    Thread Starter tina_tech

    (@tina_tech)

    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.

    Hi

    Have you tried to test it without permakinks switched on?

    kevin

    you could also try using the rewrite option:

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

    to see if that removes the additional ntnu.

    kevin

    Thread Starter tina_tech

    (@tina_tech)

    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…

    Hi

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

    http://tinahaaskjold.com/?p=123

    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.

    Kevin

    Thread Starter tina_tech

    (@tina_tech)

    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)…

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