Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am wondering if anyone could help me accomplish something like this: https://medium.com/thoughts-and-words/5ccef7b3e1fc with custom post types?

I have a custom post type called projects and custom taxonomy called project-category. I would like to show the next 3 projects in the same project-category on the single project page. One will show title and excerpt and the other two will just show titles.

share|improve this question

2 Answers 2

From what I gather all you need to do is query the 3 posts and step though each one using the_post(). I have not used it like this so not 100% that is how it works.

the_post() Retrieves the next post, sets up the post, sets the 'in the loop' property to true.

$project_query = array(
    'posts_per_page' => 3,
    'post_type'      => 'projects',
    'taxonomy'       => 'project-category'
    );

query_posts ( $project_query ); while ( have_posts() ) :  

//Post 1
the_post();
the_title();
the_content();

//Post 2
the_post();
the_title();

//Post 3
the_post();
the_title();

endwhile;
share|improve this answer
    
Bash, thanks for the response! This is almost what I need. The only problem is that this pulls the next 3 posts in any project-category. I need to pull the next 3 post in the current project category. For example, if the current post is in the web-design and identity project-category, I only want to show 3 more posts from web-design/identity. How can I modify your code to use the taxonomy term? –  Curtis Flick May 17 '13 at 13:39
    
looks like you found a good logical answer :) –  Bash May 20 '13 at 4:18

Thanks to @Bash for getting me started, I've come up with a decent solution that's working well so far.

Here's the code...

// create array of current taxonomy term slugs
$current_project_term_slugs = wp_get_object_terms($post->ID, 'project_type', array('fields' => 'slugs'));
// convert array to comma seperated values in string to query posts with same taxonomy terms
$term_slugs = join(', ', $current_project_term_slugs);
// set up query args
$project_query = array(
    'posts_per_page' => 3,
    'post_type'      => 'projects',
    'project_type'       => $term_slugs,
    'post__not_in' => array($post->ID)
    );

query_posts ( $project_query ); while ( have_posts() ) :  

// next project primary
the_post();
the_title();
the_excerpt();

// next project secondary 1
the_post();
the_title();

// next project secondary 2
the_post();
the_title();

endwhile;
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.