イベントを管理するための単純なワードプレスプラグインに取り組んでいます。
プラグイン フォルダにあるイベント ページにリンクしたいレイアウトにリンクがあります。
のような長い URL は必要ありませんlocalhost/project/wp-content/plugins/event-manager/event-page.php?eventid=1
。
のようになりたいlocalhost/project/event/1
。1
が eventid get を参照する場所。
私はたくさん検索しましたが、まだそれを機能させる方法を見つけることができません。
私のコードは次のとおりです。
register_activation_hook(__FILE__, 'link_rewrite');
function link_rewrite() {
add_rewrite_rule('^event/^[0-9]', plugins_url('event-manager') . '/event-page.php? eventid=$matches[1]', 'top');
flush_rewrite_rules(false);
}
add_filter('query_vars', 'link_rewrite_query_vars');
function link_rewrite_query_vars($query_vars) {
$query_vars[] = 'eventid';
return $query_vars;
}
誰かが解決策を持っていることを願っています。