duanhuan2301 2013-07-20 19:37
浏览 38
已采纳

如何在wordpress主题/插件中将状态标头设置为200

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.

展开全部

  • 写回答

1条回答 默认 最新

  • douzhang8840 2013-07-22 15:32
    关注

    I realized that status_header(200); actually sets the status to 200. So I had to edit my index.php to check is_404() and do accordingly.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部