I am currently working on a WordPress auction plugin. The plugin stores item in a separate table. I have successfully created the plugin and is working as expected (in the admin area).
Now I am trying to build a theme that will utilise the plugin. I need to display all the auction items in the front-end of the site. When a user visits url www.somesite.com/auctions/2
, I want to display details of auction with id 2.
I have successfully written a .htaccess redirect that will get the id, so I can use the id to find the auction in the table and display its detail. But the problem not is that WordPress displays 404 page if I visit that url.
This is what I have tried.
.hatccess
RewriteRule ^(auction)/(.*)$ ?action=$1&id=$2 [L]
So now if someone visits /auction/1
, var_dump(id)
will get me 1
. I have a Auction
class for which I intend to get the respective auction by doing $auction->get(id)
in my theme.
So far everything works fine, apart from the 404 page
I get when I visit the url. I have tried following to get rid of the 404 page
if someone visits the url.
// code below this point doesnt work as intended.
public function resolveURL(){
global $wp_query;
$action = $_GET['action'];
$id = $_GET['id'];
if($action == 'auction' && !empty($id)){
status_header(200);
$wp_query->is_page = $wp_query->is_singular = true;
$wp_query->is_404 = false;
}
}
And in my theme base.php
i call:
global $wppa; // plugin object
$wppa->resolveURL();
I want to not get the 404 page when I call the function and the url is /auction/someid
. Any help will be appreciated.
Thanks in advance.
I realized that
status_header(200);
actually sets the status to 200. So I had to edit myindex.php
to checkis_404()
and do accordingly.