[resolved] Permalinks and custom get variables - the working way (2 posts)

  1. zolchew
    Posted 6 years ago #

    For those who want to spare 5 hours of searching:

    If you want your plugin to work like:

    // this needs to run once somewhere in your setup:
    add_action('init', 'myvar_flush_rewrite');

    add_filter('query_vars', 'myvar_vars');
    add_filter('rewrite_rules_array', 'custom_rewrite_rules');

    function myvar_flush_rewrite() { global $wp_rewrite; $wp_rewrite->flush_rules(); }

    function myvar_vars($public_query_vars) { $public_query_vars[] = 'custom_param';
    return $public_query_vars; }

    function custom_rewrite_rules($existing_rules) {
    $new_rules = array('(yourplugin)/custom_param/([^/]+)/?$' => 'index.php?pagename=yourplugin&profil=$matches[2]');
    $existing_rules=$new_rules + $existing_rules;
    return $existing_rules;}

    function some_plugin_function(){
    echo get_query_var('custom_param');
    // you'll get custom_variable here

  2. brainspiral
    Posted 6 years ago #

    Anyone know why this doesn't work in WP3? This used to work in WP2.x (though 2.92 anyway)

Topic Closed

This topic has been closed to new replies.

About this Topic