So, I'm doing some wordpress development studies and classes, and now I got an project to work on, and need to get the following task done: I'm doing a telecom website. The site has a page called "Buy" with its custom template. The ideia is that all other pages of services are linking to this page. I want this page to handle all service "order" requests from users.

So it would look like this: www.example.com/buy/

And let's say, the user choose the 50MB Fiber internet plan: www.example.com/buy/?product=fiber50

Conclusion, if "Buy" page comes with "product" URL parameter, the content of the page should change too, because the prices, description and other details are different from each internet plan or other kind of service.

I'm struggling to find a solution for that, but i've researched a lot the past few days and didn't find any solution.

Think would be something like that: https://stackoverflow.com/questions/15099821/wordpress-accept-incoming-url-with-variable-parameters

Thank you by any help!

1 Answer 1


My suggestion would be to use a custom page template. In your functions file you require a php file that contains the custom template.

require_once 'buy_page_template.php';

and that file declares itself to be a template by containing some commented out text:

/* Template Name: Buy Page */

Once you've uploaded and required that file, a new template appears as a possibility in all your pages in Wordpress. You just set the page "buy" to use that template. You can put all the PHP you want into that template, and access the GET variable coming in just like you saw in the other question you cited.

What I do is copy and modify a template file from the theme I'm using.

  • Thanks @Elkrat that's exactly what I did and actually worked very well! But I still got blocked when I think of how can I get the "service information"? Do you have any ideia of how can I achieve that? Using $_GET I will be able to extract only the query passed right? Apr 3, 2020 at 17:26
  • You use the information from the GET variable to go look up whatever information you need from the database. The you're echoing your page with the relevant data. So if you have a product that's post #3567 (coming is as ?prod=3567) then you may, depending on your data model, grab the post metas from that post. e.g. $prod_price = get_post_meta(intval($_GET['prod']), '_price', true); and so on. Notice how intval sanitizes input when you know it should be an integer value. Trust no one :)
    – Elkrat
    Apr 4, 2020 at 18:55
  • Where does "service information" live? Is that a meta entry for a post called "50MB Fiber" or similar?. And if "service information" is a field that is meant to be edited on the custom post type of Services, then it will probably not start with a dash. So my example was off. You would probably say $prod_id = intval($_GET['prod']); $service_desc = get_post_meta($prod_id, 'service_description', true);
    – Elkrat
    Apr 4, 2020 at 19:00

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.