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 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥15 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)