WordPress.org

Ready to get started?Download WordPress

Forums

custom post template not working with Custom Post Type posts (7 posts)

  1. juliabarry
    Member
    Posted 1 year ago #

    I made a Custom Post Type and a post template that I want to associate with it, and got it properly rigged up so I can choose the template as an option from the Custom Post Type page.

    The post template works just great with regular posts, but when I assign that same post template to a Custom Type post, no dice. My guess is the default template is overriding, or somehow getting pulled in b/c the template isn't "seen" correctly for the Custom Post, but I'm not sure and don't know how to fix.

    Any thoughts on how to troubleshoot this?

    Thanks!

  2. Andrew Bartel
    Member
    Posted 1 year ago #

  3. juliabarry
    Member
    Posted 1 year ago #

    Thanks, will give it a go and let you know what happens!

  4. Andrew Bartel
    Member
    Posted 1 year ago #

    Sure thing, let me know if you run into any issues.

  5. juliabarry
    Member
    Posted 1 year ago #

    Ok, I'm definitely doing something wrong ;)

    When I use this secondary query, something weird happens. The URL in the address bar is http://juliabarry.com/webdesign/erin_trahan/erin-trahan/ but I get an error message that says "You tried going to http://juliabarry.com/webdesign/webdesign/erin_trahan/erin-trahan/, and it doesn't exist. All is not lost! You can search for what you're looking for."

    Here's my post template code. Lemme know where I'm going wrong...

    <?php
    /*
    Template Name Posts: ErinTrahan.com
    */
    
    $args = array('post_type' => 'erin_trahan','post_count'=> 50);
    $erin_query = new WP_Query($args); // Instantiates new WP_Query object for Erin Trahan Custom Post Type posts
    
    get_header(); // Loads the header.php template. ?>
    
    	<?php do_atomic( 'before_content' ); // hatch_before_content ?>
    
    	<div id="content">
    
    		<?php do_atomic( 'open_content' ); // hatch_open_content ?>
    
    		<div class="hfeed">
    
    			<?php if ( $erin_query->have_posts() ): while ( $erin_query->have_posts() ): $erin_query->the_post(); ?>
    					<?php do_atomic( 'before_entry' ); // hatch_before_entry ?>
    
    					<div id="post-<?php the_ID(); ?>" class="<?php hybrid_entry_class(); ?>">
    
    						<?php do_atomic( 'open_entry' ); // hatch_open_entry ?>
    
    						<div class="post-content">
    
    							<?php if ( current_theme_supports( 'get-the-image' ) ) get_the_image( array( 'meta_key' => 'Thumbnail', 'size' => 'single-thumbnail', 'link_to_post' => false, 'image_class' => 'featured', 'attachment' => false, 'width' => 640, 'height' => 360, 'default_image' => get_template_directory_uri() . '/images/single_image_placeholder.png' ) ); ?>
    							<div class="post-aside">								
    
    								<?php echo apply_atomic_shortcode( 'entry_title', '[entry-title permalink="0"]' ); ?>
    
    								<?php echo apply_atomic_shortcode( 'byline_date', '<div class="byline byline-date">' . __( '[entry-published before="Date: "]', 'hatch' ) . '</div>' ); ?>
    
    								<?php the_field('project_url'); ?>
    
    								<?php echo apply_atomic_shortcode( 'byline_category', '<div class="byline byline-ategory">' . __( 'Category: [entry-terms taxonomy="category"]', 'hatch' ) . '</div>' ); ?>
    
    								<?php echo apply_atomic_shortcode( 'entry_meta', '<div class="entry-meta">' . __( '[entry-terms taxonomy="post_tag" before="Tags: "]', 'hatch' ) . '</div>' ); ?>
    
    								<?php the_field('project_description'); ?>
    
    								<?php echo apply_atomic_shortcode( 'byline_edit', '<div class="byline byline-edit">' . __( '[entry-edit-link]', 'hatch' ) . '</div>' ); ?>
    
    								<?php get_template_part( 'loop-nav' ); // Loads the loop-nav.php template. ?>
    
    							</div>
    
    							<div class="entry-content">
    								<?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'hatch' ) ); ?>
    								<?php wp_link_pages( array( 'before' => '<p class="page-links">' . __( 'Pages:', 'hatch' ), 'after' => '</p>' ) ); ?>
    							</div><!-- .entry-content -->
    
    							<?php do_atomic( 'close_entry' ); // hatch_close_entry ?>
    
    						</div><!-- .post-content -->
    
    				</div><!-- .hentry -->
    
    					<?php do_atomic( 'after_entry' ); // hatch_after_entry ?>
    
    <!-- ========== ///// BEGIN IMAGE GRID ========== -->	
    
    <?php query_posts('category_name=ErinTrahan&posts_per_page=10'); ?>
    
    <div id="project-images">
    <?php while (have_posts()) : the_post(); ?>
    
    		<div class="left highlight"> 
    
    				<a href="http://juliabarry.com" title="<?php the_field( 'image_title' ); ?>"><img src="<?php the_field( 'project_image' ); ?>" alt="<?php the_field( 'image_alt_info' ); ?>" width="290"></a>
    				</div>				
    
    				<?php endwhile;?>
    				</div>
    
    <!-- ========== END IMAGE GRID \\\\\ ========== -->	
    
    					<?php do_atomic( 'after_singular' ); // hatch_after_singular ?>
    
    				<?php endwhile; ?>
    
    			<?php endif; ?>
    
    		</div><!-- .hfeed -->
    
    		<?php do_atomic( 'close_content' ); // hatch_close_content ?>
    
    	</div><!-- #content -->
    
    	<?php do_atomic( 'after_content' ); // hatch_after_content ?>
    
    <?php get_footer(); // Loads the footer.php template. ?>

    Thanks!!

  6. Frumph
    Member
    Posted 1 year ago #

    .. if your custom post type didn't flush the rewrite, you need to go to settings -> permalinks and click 'save' once so that it flushs and recreates them there.

    Otherwise you would get 404 errors or not able to redirect properly to the template you want.

  7. juliabarry
    Member
    Posted 1 year ago #

    That helped to get rid of the error, thanks! But now I'm back to the original problem, where the post format is just going to the default. My code for the secondary query is still the same as above. Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic