I have three different posts in a custom post type (services), and when i open one of these in single.php I want to show posts from another custom post type(projects) under the main-post. But I only want to show posts from projects that is related with the post from services.
Like, IF post from “services” has ID 1, show post from “projects” tagged “service1”.
Thanks for the answer! However, I need to do this dynamically. I need to connect certain posts from a post type with certain posts from another post type. And I don’t know how to do this.
On the first-page you see three posts/sections named “byggnation”, “fasadrenovering”, “fastighetsfövaltning”, these belong to the same post-type. And if you click “läs mer(read more)” you open single.php and display the whole post. Inside the post you can see “utförda projekt” to the right. This is another post type, that displays different projects for the specific service/post you clicked.
ATM “utförda projekt” displays ALL projects from the three different services that i wrote above. The thing I want to do is to only show the projects that is related to the opened post.
Thanks but I don’t think it will solve my problem. Here is how my loops for single.php looks ATM:
<!-- DISPLAY SINGLE POST -->
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php endwhile; else: ?>
<p>There are no posts</p>
<?php endif; ?>
<!--- DISPLAY PROJECTS -->
<?php
$args = array(
'post_type' => 'projects'
);
$the_query = new WP_Query( $args );
?>
<?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php endwhile; else: ?>
<p>There are no posts</p>
<?php endif; ?>
The first loop gets the single post when the user clicks the “read more” button.
The second loops gets the projects. And this one have to get the right project-posts depending on what post is displayed by the first loop. Like if the first project has ID=1 the second loop displays post with the tag “service1”. And because of this is the single-post.php I can’t really do it your way because that would show the same result regarding what post the visitor opens? right?