Query same category posts in Oxygen repeater and exclude current post

Here is a tutorial on how to create a “related posts” repeater where categories of the post you are currently viewing will be queried whilst excluding the current post itself for better user experience.

My past iterations of this website used to have a sidebar which would always show the most recent 6 posts of the same category as the current post but excluding the current post. This is a fantastic way to allow users to explore more posts without having to go to a post archive page or simply exit the website. In fact, after doing this, my GA bounce rate saw some serious improvements!

I’m sure there is an easy way to do this but here is how I achieved this (please note, I will skip the styling portion):

The steps

Query dynamic data

Drop in an Oxygen repeater element wherever you want to show the post list and then drop in elements to query the relevant dynamic data as you require.

For example, I will simply drop in a heading (h4) element > double click on the default text > select Dynamic Data > select Post Title > check the Link option.

Doing the above steps will allow us to quickly see if the repeater query is working correctly.

You can of course style all these elements at any time as per your design requirements.

Query repeater

Go to the repeater panel > select Query > under Advanced > select Edit Query > then clear any queries that may be there by default by clicking on the bin icon and add the following queries:

Note: Please remove the space between the square brackets below!

  1. post_type --> [ oxygen data='post_type' ]
  2. tax_query --> array
    • taxonomy --> category
    • terms --> add value --> [ oxygen data="post_terms" taxonomy="category" ]
    • field --> slug
  3. no_found_rows --> true
  4. posts_per_page --> 6 (you can change this number to the maximum number of items you want to display)
  5. post__not_in --> [ oxygen data="id" ]

Once you have added the above queries, you can close the query pane and then click save on the top right of the Oxygen editor.

Provided you correctly added the above queries, you should now see the correct type and number of posts in the front-end.

Want to be notified of new posts like this?

Sign up to be notified of new posts using the form below. Email addresses are used for the sole purpose of sending once-in-a-while email notifications and nothing else. I promise I don't spam!