plugin development - Generate Static Page to Show Search ResultsDetail for API

I'mfairly new to WordPress, but well seasoned in PHP. I've looked around for other examples, and most of the

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?

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?

Share Improve this question asked Jul 11, 2019 at 14:45 SimonSimon 1113 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

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/resultpagename" method="post">
  <input type="text" name="search" />
</form>

In your result template:

$search_query = $_POST["search"];

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

var_dump($data);

Let me know if this works or not.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745329733a4622821.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信