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

How to generate query string for Easy Posts and Repeaters in Oxygen

Sridhar Katakam

When you want to write a manual query in an Easy Posts element, the input needs to be a valid query string.

Almost all the code examples out there are given as arrays that contain key-value pairs like the following:

	'post_type' => 'page',
	'post__in'  => array( 2, 5, 12, 14, 20 ),

The above will fetch Pages that have the specified IDs.

But how do we convert the above to a query string that can be added in Easy Posts?

WordPress’ build_query function to the rescue.

Here’s how this can be used:

Step 1

Add a Code Block element (doesn’t matter where – this is just a temporary thing) and inside the PHP & HTML, add

$data = array(
	'post_type' => 'page',
	'post__in'  => array( 2, 5, 12, 14, 20 ),

echo build_query( $data );


	'post_type' => 'page',
	'post__in'  => array( 2, 5, 12, 14, 20 ),

with your custom query.

Step 2

Save the entry and view it on frontend. Copy the generated code.

Step 3

Edit your Easy Posts element. Go to Query > manual, paste the code.

Apply Query Params.

Easy Posts should now use the query you provided.

Step 4

Delete the Code Block.