• Resolved zolchew

    (@zolchew)


    For those who want to spare 5 hours of searching:

    If you want your plugin to work like:
    https://www.example_wp_page.com/yourplugin/custom_param/custom_variable

    // 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
    }

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Permalinks and custom get variables – the working way’ is closed to new replies.