12% off of LTD using this coupon: TWELVEPERCENTOFF. Promo ends on 2 Dec midnight UTC.
Published on Apr 26, 2019

How to output a random single post from a random category in Oxygen

Sridhar Katakam

In the Oxygen's Facebook group a user asked:

Hi, How do i have Easy Posts post 1 category in a random order?

Making the above work involves

  • getting a list of all categories
  • looping through the above list and storing the IDs of all the categories in an array
  • writing a custom query + loop where in we pass a random ID from the above array as the value of "cat" and ask WP to pull just 1 random post from that category.

As can be seen from the logic, there are a few moving or dynamic parts to achieve our end goal and as such, this is not possible using Oxygen's Easy Posts component.

This members-only tutorial provides the steps to use a Code Block component to pull one random post from a random category using a custom WordPress query with the loop part taken from one of the Easy Posts' presets.

Step 1

In the Oxygen editor, add a Section.

Add a Code Block inside.

PHP & HTML:

This is a premium members-only content.

To view the rest of the content, please sign up for membership ($47/month or $599 one-time).

Already a member? Log in below or here.

tagschevron-leftchevron-rightchainangle-rightangle-upangle-downfolder-omagnifiercrossmenuchevron-downarrow-right