Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Tim Geaney
Tim Geaney
7,818 Points

I have a problem when using custom post types the permalink

Hello,

I have a problem when using custom post types. The permalink that wordpress automatically gives you for the custom post type is redirecting to index.php. So it obviously cant find permalink and is just reverting to next available page. Any ideas?

Kind Regards,

Tim

Jonathan Selwall
Jonathan Selwall
12,528 Points

Have you tried deactivating your plugins to see if any plugin might be causing this?

Also sometimes it bugs out when you create a custom post type after changing the permalink structure so try and reset the permalink structure. Go to: Settings > Permalinks > change back to the default structure and save, then go back to your custom structure and save.

If this doesn't work, show us some code!

1 Answer

Tim Geaney
Tim Geaney
7,818 Points

Hi Jonathan,

Thanks for your help but I deactivated all plugins no joy then reset permalinks no joy. It just keeps giving error message 404 page not found or reverting to index.php.

Not sure what code to show you but here is the page-portfolio.php file that custom post type loops through. I'm following the build a wordpress theme tutorials.

''' php <?php

/* Template Name: Portfolio Page */

?>

<?php get_header(); ?>

<section class="image-bg bg-blue overlay "> <div class="background-image-holder"> <img alt="Background Image" class="background-image" src="img/project-single-3.jpg"> </div> <div class="container"> <div class="row">

            <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

            <div class="col-sm-12 text-center">
                <h2 class="uppercase mb8"><?php the_title(); ?></h2>
                <p class="lead mb40">Solar Adtek offer a range of Solar solutions for outdoor advertising.</p>
            </div>

           <?php endwhile; endif; ?>
        </div>

    </div>

</section>

<?php

$args = array(
    'post_type' => 'portfolio'
    );
$query = new WP_Query( $args );

?>

<section class="projects"> <div class="container">

  <div class="row">

      <?php  if( $query->have_posts() ) : while( $query->have_posts() ) : $query->the_post(); ?>

      <div class="col-sm-6 project" data-filter="People">
          <div class="image-tile hover-tile text-center">
              <?php the_post_thumbnail('large'); ?>
              <div class="hover-state">
                  <a href="<?php the_permalink(); ?>">
                      <h3 class="uppercase mb8">Advertising Illumination</h3>
                      <h6 class="uppercase">Learn More</h6>
                  </a>
              </div>
          </div>
          <!-- END PROJECT -->
            </div>
        <?php endwhile; endif; wp_reset_postdata(); ?>
      <!-- END ROW -->
  </div>
    <!-- END CONTAINER -->

</div> <!-- END SECTION PROJECTS --> </section>

<?php get_footer(); ?>

'''