I am developing a e-commerce theme that requires an order page. I created a php file inside my theme folder named order-page.php and hope to access this page from the wordpress root url (example.com/order-page)
add_action('template_redirect', 'template_redirect');
function template_redirect(){
$basename = basename($_SERVER['QUERY_STRING']);
echo $basename;
if($basename=='order-page'){
loadCustomTemplate(TEMPLATEPATH."/$basename.php");
}
}
function loadCustomTemplate($template) {
global $wp_query;
if(!file_exists($template)){
return;
}
$wp_query->is_page = true;
$wp_query->is_single = false;
$wp_query->is_home = false;
$wp_query->comments = false;
// if we have a 404 status
if ($wp_query->is_404) {
// set status of 404 to false
unset($wp_query->query["error"]);
$wp_query->query_vars["error"]="";
$wp_query->is_404=false;
}
// change the header to 200 OK
//header("HTTP/1.1 200 OK");
//load our template
include($template);
exit;
}
Problem#1: with the function listed above, I can only use example.com/?order-page to get what I want. If I use example.com/order-page, I will get url not found
error.
Problem#2: when I have multiple parameters, this function doesn't work anymore. For example, if I have:
example.com/?order-page&product_id=001&type=digital
$basename
will return order-page&product_id=001&type=digital
Using $query_array=explode('&',$basename)
and get $query_array[0]
is one possible solution. Is there a better way to do this?