Get Query Loop Result via PHP

Is there a filter that gets the resulting post IDs from a query loop in PHP?

I have a template that uses a query loop. But depending on the settings of the queried posts, the result varies. I want to add a button to that template that saves the current list of posts. To achieve that, I need the post IDs in a PHP function that is being triggered by the button. Is there an option to get the results of a query loop not just on the frontend but also in the backend?

You might be looking for this: Filter: bricks/query/result – Bricks Academy . There you will get all the resulting post ids.

If you need to do it via button-click I cannot think of a simple solution.
You could add the post-id via data-attribute to each list-item. Then on button click you could trigger a java-script function to read all the ids from the data-attribute and save them in an array. You would then have to make an ajxa-call to call your php-function and pass the ids.

Hope it helps!

Thank you! That seems to work. I would rather create a transient and upon button click read that transient to store the result permanently in a CPT. It seems to work even with WP Gridbuilder, so I can omit the filters.