404 page not found error with pagination and permalinks on custom post type
-
i have created a custom post type in wordpress by adding the following to my custom themes function.php
function oil_paintings_init() { $args = array( 'labels' => array( 'name' => __( 'oil-paintings' ), 'singular_name' => __( 'oil-painting' ), 'rewrite' => array( 'slug' => 'oil-painting'), ), 'public' => true, 'show_ui' => true, 'capability_type' => 'post', 'hierarchical' => false, 'query_var' => true, 'menu_icon' => 'dashicons-format-image', 'supports' => array( 'title', 'editor', 'revisions', 'page-attributes',) ); register_post_type( 'oil-paintings', $args ); } add_action( 'init', 'oil_paintings_init' );
I have created a custom page template which loops and displays the posts from the custom post type i have added above . I want to show 5 posts at a time and rest by next and previous links on the page. This is the code which i have used:
<?php if($wp_query->have_posts()): while($wp_query->have_posts()) : $wp_query->the_post(); ?> <div class="columns"> <img src="<?php the_field('image1'); ?>" alt="" /> <a href="<?php the_Permalink(); ?>"><?php the_title(); ?></a> </div> <?php endwhile; next_posts_link("next"); previous_posts_link("prev"); endif; wp_reset_postdata(); ?>
The problem i am facing is when i enable permalinks in my wordpress to
‘https://www.domainname.com/%postname%/’ –>this does not work
the next and previous posts link stop working and i get a page not found error. everything works ok if my permalinks is set to plain
‘https://www.domainname.com/?p=123’ –> this works
any help in this regard is aprreciated. Thanks
- The topic ‘404 page not found error with pagination and permalinks on custom post type’ is closed to new replies.