0
votes

I've run into the following problem. I have a custom post type named books and a page named books. Now I want to output the posts that my custom post type holds onto the page named books.

I'm using the following query:

        <?php
        $args = array( 'post_type' => 'books');
        $loop = new WP_Query($args);
        while ($loop->have_posts()) {
            $loop->the_post();
    ?>
        <div <?php post_class('col-lg-5'); ?> id="post-<?php the_ID(); ?>">
            <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
            <?php the_content(); ?>
        </div>
    <?php
        }
    ?>

Problem is, It keeps reverting to my archive.php, even If I choose the books template. If I change the url to /books2/ it works fine, but if I use /books it points me to the archive.php.

I've disabled the has_archive arg in my functions.php and I don't really know what else to do.

It's fairly simple, I don't want a archive to exist, instead I want to output my custom posts on a page.

1

1 Answers

0
votes

Try this, When you are registering the custom post, rewrite the post slug with different name (other than "books")

'rewrite' => array(  
 'slug' => __( 'book' )  
), 

add this argument in $args array. and then try.