Easy Related Posts WordPress Query

Sometimes you just need to output some posts based on the post you are already on. You could place this code on your single post template and it would return 3 posts based on the categories said post are associated with. The 'post__not_in' => array(get_the_ID()), line ensures the post you are currently on doesn’t show in this list. You could also replace 'category__in' => wp_get_post_categories(get_the_ID()), with 'tag__in' => wp_get_post_tags(get_the_ID()), to base this query off Tags instead of Categories.

I am hoping in the near future this is something that can be achieved with the Full Site Editor and the Query block.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.