• Resolved bkdimri

    (@bkdimri)


    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%/&#8217; –>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&#8217; –> this works

    any help in this regard is aprreciated. Thanks

Viewing 8 replies - 1 through 8 (of 8 total)
  • just 404 and 403 page are not yet setup, depends on apache or nginx,

    Thread Starter bkdimri

    (@bkdimri)

    @digio paris.. i did not understand. The 404.php page is there

    ok sorry,

    the full test i was calling you is, if nginx works then a db too.

    afer, depends how you set it up.

    did you try theme or template as native in like functions.php?

    Thread Starter bkdimri

    (@bkdimri)

    do you mean ” did i create a custom theme” .. the answer is yes.

    Thread Starter bkdimri

    (@bkdimri)

    hi everne,
    kind of stuck here. any help in this regard is appreciated
    thanks

    Thread Starter bkdimri

    (@bkdimri)

    ok finally found the solution. Moved the rewrite out of the labels array.
    the following modified code in funtions.php did the job for me

    function oil_paintings_init() {
    $args = array(
      'labels' => array(
        'name' => __( 'oil-paintings' ),
        'singular_name' => __( 'oil-painting' )
      ),
        'public' => true,
         'rewrite' => array( 'slug' => 'oil-painting'),
        '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' );
    Thread Starter bkdimri

    (@bkdimri)

    the above post resolved it

    Digico Paris

    (@digico-paris)

    ok thank you bk, hope your code will help other people:)

    have fun with wp,

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘404 page not found error with pagination and permalinks on custom post type’ is closed to new replies.