2011-10-03 16 views
3

我正在編寫一個插件,它將URL路由到自定義格式。WordPress的 - 我可以得到一個給定的路徑重寫規則?

很簡單,我想要得到給定路徑的重寫規則,我可以這樣做嗎?

因此,例如,我需要一個函數如下:

$path = 'team/john-smith'; 

$rules = get_rules($path) 

$規則現在是一樣的東西

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

或替代,實際重寫規則陣列(和我可以生成字符串我自己...)

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

回答

0

你看過includes/rewrite.php中的這個函數嗎:

function url_to_postid($url)

我的猜測是,獲得實際的重寫規則,你可以使用:

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

或致電page_rewrite_rules()。該文件中有幾個有趣的代碼。