Reputation: 2456
I try to create a template for a custom post type, so I registered the post type:
function aran_create_post_types(){
register_post_type('aran_agencies',
array(
'labels' => array(
'name' => __( 'Agencies', 'aran' ),
'singular_name' => __( 'Agencies', 'aran' ),
'add_new_item' => __( 'Add new agency', 'aran' ),
),
'public' => true,
'has_archive' => true,
'supports' => array(
'title',
'editor',
'thumbnail',
'custom-fields',
),
)
);
}
add_action( 'init', 'aran_create_post_types' );
Then, I create a file called "single-aran_agencies.php", and put the following code:
echo "this is single agency page";
But when I try to view an agency post, I get 404 page. the same happen with the archive page. Here is my single.php code, which I inherit from a parent theme:
get_header();
$show_sidebar = get_post_meta($post->ID, 'show_sidebar_checkbox', true);
if ( $show_sidebar == 'yes' ):
$bootstrap_sidebar_dep = 'col-sm-8';
else:
$bootstrap_sidebar_dep = 'col-sm-12';
endif;
?>
<div class="container">
<div class="row">
<div id="primary" class="content-area <?php echo apply_filters('primary_bootstrap_class', $bootstrap_sidebar_dep); ?>">
<div id="content-top-wa" class="widget-area">
<?php dynamic_sidebar('content-top') ?>
</div><!-- #content-top-wa -->
<main id="main" class="site-main" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'single' ); ?>
<?php faster_post_nav(); ?>
<?php
// If comments are open or we have at least one comment, load up the comment template
if ( comments_open() || '0' != get_comments_number() ) :
comments_template();
endif;
?>
<?php endwhile; // end of the loop. ?>
</main><!-- #main -->
<div id="content-bottom-wa" class="widget-area">
<?php dynamic_sidebar('content-bottom') ?>
</div><!-- #content-bottom-wa -->
</div><!-- #primary -->
<?php
if ( $show_sidebar == 'yes' ):
get_sidebar();
endif;
?>
</div><!-- .row -->
</div><!-- .container -->
<?php get_footer(); ?>
What am I doing wrong here?
Any help will be appreciate!
Upvotes: 0
Views: 52
Reputation: 106
Try this:
Create a new WP_Query for your new post type so that you'd add:
// Args for your Post Type:
$args = array (
'post_type' => array( 'aran_agencies' ),
);
// The New Query
$agencies = new WP_Query( $args );
Then you could replace:
while ( have_posts() ) : the_post();
With
while ( $agencies->have_posts() ) : $agencies->the_post();
Upvotes: 0