I'm fairly new to WordPress, but well seasoned in PHP. I've looked around for other examples, and most of the code samples I see are all about creating posts and hooking around the search results list to customise the display.

What I have is a web form in WordPress that I intercept and pass the query to an external API and get a list of results back. I don't want to use an IFRAME.

Currently at the moment, what I have is a form that gets shown when a short code is specified on a page, but when someone clicks the search button, the form action is blank so it goes back to the same page, and if it detects that the "button" is in the post back vars, it gets the results from the API and displays them. If the button isn't there it displays the form.

But there's two things from that. I need a dedicated results page. The search form could appear anywhere and formatted in any way, it may be horizontal, across the page, vertical in a side bar, or just big and bold in the main body.

On top of this, I need to be able to click on one of the entries in the results to be able to drill down deeper into specific information.

What is the best way of achieving this? Being PHP minded, Im thinking somehow programmatically registering two URL's or Pages that I can set my form action to. Or as has just come to me, whether what I need to do, is to create two new dynamic pages with two new short codes such as "short_code_result_list" and "short_code_result_detail", register those short codes and then call the functions in the usual way checking for the appropriate GET/POST variables, taking the appropriate action as we're doing already to generate the list and referring the user back to the previous page if those variables are not set.

How would you achieve this?

1 Answer 1


I'm not so professional in this but I have a solution you can try. You can create custom page templates in WordPress and place your form code in that template and in another template create your result page and pass the query using POST method to the result page template. Then with php you can get the search query using $_POST and get information from your API. I've done this same thing with one of my plugins.

In your search form template:

<form action="yoursiteurl.com/resultpagename" method="post">
  <input type="text" name="search" />

In your result template:

$search_query = $_POST["search"];

$response = wp_remote_get('https://ecourier.com.bd/apiv2/?product_id=' . $search_query);
$body = wp_remote_retrieve_body( $response );
$data = json_decode( $body, true );


Let me know if this works or not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.