You want to use admin-post.php
or admin-ajax.php
(AJAX only) to allow your front-end form to interact with WordPress.
Setting this up will allow you to create an action where you use the $_POST
array to find the content you’re looking for with WP_Query
and print it out as the response to your request.
Here’s a decent guide to both methods: https://premium.wpmudev.org/blog/handling-form-submissions/