【问题标题】:Wordpress - can I get rewrite rules for a given path?Wordpress - 我可以获得给定路径的重写规则吗?
【发布时间】:2011-11-30 02:32:50
【问题描述】:

我正在编写一个插件,它将 URL 路由到自定义格式。

很简单,我想获得给定路径的重写规则,我可以这样做吗?

例如,我需要一个函数如下:

$path = 'team/john-smith';

$rules =  get_rules($path)

$rules 现在类似于

index.php?team=john-smith&post_type=team&name=john-smith;

或者,实际的重写规则数组(我可以自己构建字符串...)

array("team" => "john-smith", "post_type" => "team", "name"=> "john-smith");

【问题讨论】:

    标签: wordpress url-rewriting


    【解决方案1】:

    你在includes/rewrite.php中看过这个函数吗:

    function url_to_postid($url)

    我的猜测是,要获得实际的重写规则,您会使用:

    global $wp_rewrite;
    $rewrite = $wp_rewrite->wp_rewrite_rules();
    

    或致电page_rewrite_rules()。该文件中有一些看起来很有趣的代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-26
      • 1970-01-01
      • 2016-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多