Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

WordPress

Konrad Pilch
Konrad Pilch
2,435 Points

Custome Post Type not working how it shoudl

Hi,

I have Custom Post Type and a single-services.php

Now, it displays the posts i have in Services, but it displays only the recent post that i added.

If i click on business-consulting or tax-consulting or any other , it will display me the recent post added instead of following the slug of displaying the post of tax-constuling and so on.. i have the links in the navigation bar in submenu that are linked with custom post types.

it doesn't work, how can i get the right title, image and description when doing this? So it displays the right post? not the recent one?

I have events page as well and it has the same problem.

1 Answer

Konrad Pilch
Konrad Pilch
2,435 Points

:DDD

  <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
              <article class="white-bg">

                <img class="image-thumbnail" src="<?php echo get_field( 'service_image'); ?>">

                <div class="service-content-wrapper border-rd">
                     <h1 class="text-heading"><?php the_title(); ?></h1>
                     <p class="text-muted">
                        <?php the_content(); ?>
                     </p>
                  </div>
              </article>
            <?php endwhile; endif; ?>

Since the page is called single-services.php it already know that im calling it from services or somehting.. so i didn't had to have wp_query, insead i just had to have a normal loop, or i coud do it even without, but because i wanted to have the_content() i needed the loop with nothing in it and it has worked! :D

Took 2-3 days to figure this out :D