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.

Is there a simple way to get related posts without having to use a plugin? I am preferably looking for something really simple like a couple lines at most

I currently use this to get random posts, but would like to get random related posts instead

  <?php $args = array( 'orderby' => 'rand', 'numberposts' => 4 ); $posts2 = get_posts( $args ); foreach($posts2 as $post) { ?>

Any suggestions for a lite solution?

share|improve this question

1 Answer 1

sure you can get related posts very easy:

→ post type: 'post_type' => 'your_post_type'
→ category: 'category' => 'your_category'
→ post parent: 'post_parent' => 'your_parent_ID'

those are all relationships, you can do this for taxonomies and custom fields too, just take a look at the codex: http://codex.wordpress.org/Template_Tags/get_posts

share|improve this answer

Your Answer


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.