How to add input fields to custom query loop

Hey,

I’ve successfully set up a custom query using the following hooks as per the Bricks Academy docs.

bricks/setup/control_options
bricks/query/run
bricks/query/loop_object

/* Add new query type controls to query options */
add_filter('bricks/setup/control_options', 'rgt_add_new_query_type_controls');
function rgt_add_new_query_type_controls($control_options)
{
  /* Adding new options in the dropdown */
  $control_options['queryTypes']['mls_image_custom_query'] = esc_html__('MLS Images');

  return $control_options;
};

image

This works fine, but now I need to extend the query to include custom options like Offset and Posts Per Page. How can I add option fields to the query in the builder?

Thanks :slight_smile:

See this:

Cheers

Patric

2 Likes

By the way…

now that we have the query editor (PHP), I feel we do no longer need to make custom queries.

I add my PHP code directly into the query editor and as long as I always end the code with

return [
 ...here go the query arguments
];

it works perfectly.

Cheers

Patric

1 Like

Thanks Patric,

I already used Itchcode’s guide to set up my custom query params.

Next time I’ll check out the query editor, didn’t know about it until now.

Thanks so much for your help :slightly_smiling_face:

Just had a look at the query editor, looks very useful. In my case my custom query loop is actually not a WP Query so wouldn’t have worked, but good to know its there for future use :+1:

1 Like

I need the same functionality since I am building a custom query loop from a json object. The provided solution above does not seems like a native solution since the inputs are not added to the query loop dialog itself, but the content tab.

It will be good if this functionality is provided in a better and easy way.