I am new to WordPress and I'm wondering if anyone could help me understand how I should go for rendering the output of a plugin when a form of a widget is submitted in the front-end.
I'm developing a plugin that has two "views" and one widget. The widget is just a form with a dropdown menu to select a value from a list. When a value is selected, the form should submit this value to a page where the first view of the plugin is rendered. This first view should print links that take the visitor to the second view, like the first view is a list of rows, and the second view is the details of the row selected from the first view. This is the goal.
I've been reading the Plugin API, but I don't seem to have found a proper solution. My question is: should I only rely on the Shortcodes
put on certain pages to render the plugin in the front-end? Is this the only way?
I tried to submit a custom action
with the form of my widget (with action get_admin_url().'admin-post.php'
), and hook it in the plugin with:
add_action('admin_post_customaction', 'handle_customaction');
add_action('admin_post_nopriv_customaction', 'handle_customaction');
function (handle_customaction) {
//do something
}
but the page admin-post.php truncates the execution, so I guess this practice is only for executing tasks and then redirect, not to display content within a page in the front-end.
Is there a solution beside using Shortcodes? Because then my question would be "which action attribute should I use in the form of the widget?", like how do I know which pages use the Shortcode I need?
Maybe by creating a custom post type
? Do you know any plugins that do something similar that I could check? Any hints would be much appreciated!