• I’ve been going over this for the better part of the day and I can’t figure out how to get permalink for my plugin working.

    I’ve seen the codex referencing to Jeromes keyword plugin, I’ve downloaded the plugin and stripped it to make some sense of it, but I still can’t get this to work.

    Here’s what I want to do.

    I have a plugin that get data from a custom table and displays the info. Works fine and dandy. This plugin wants a queryvar date=2006/12/31. What I want is a url like so: url.com/partyguide/2006/12/31

    For some reason, I can’t seem to add custom rewrite rules to WP. I could really use some help on this one.

    Any plugin coders out there?

    ps. here is my current code:


    <?php
    /*
    Plugin Name: Agenda
    Plugin URI: None
    Description: Shows parties on certain date.
    Version: 1.0
    Author: Megamuch
    Author URI: https://bcn-nightlife.com
    */
    /*1. Rewrite the URL so that it puts the path components into query variables, like so:*/
    add_filter( 'search_rewrite_rules', 'foo_rewrite_rules' );
    function foo_rewrite_rules ( $rewrite ) {
    global $wp_rewrite;
    // add rewrite tokens
    $wp_rewrite->add_rewrite_tag( '%fooaction%', '(.+)', 'fooaction=' );
    $foo_structure = $wp_rewrite->root . "partyguide/%fooaction%/";
    $foo_rewrite = $wp_rewrite->generate_rewrite_rules($foo_structure);
    return ( $rewrite + $foo_rewrite );
    }
    //2. Tell WP about the fooaction query variable:
    add_filter( 'query_vars', 'foo_query_vars' );
    function foo_query_vars ( $vars ) {
    $vars[] = "fooaction";
    return $vars;
    }
    //3. Write an is_foo() function so we can tell when we are in the foo 'application':
    function is_foo () {
    global $wp_query;
    return $wp_query->get( "fooaction" );
    }
    //4. Finally, override template reidrection to return the relevant foo page templates if we are in the foo application:
    add_filter( 'template_redirect', 'foo_redirect' );
    function foo_redirect () {
    if ( is_foo() ) {
    include( ABSPATH . 'wp-content/plugins/agenda/main.php' );
    exit;
    }
    }
    ?>

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘rewrite help in plugin’ is closed to new replies.