duanhuan2301 2013-07-21 03: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 23: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.

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

报告相同问题?

悬赏问题

  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计