Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Trying to get pretty permalinks happening for a plugin that displays events

I have this:

function my_add_rewrite_rules() {

  global $wpdb;
  $org_options = get_option('event_settings');      
  // get id for events page     
  $event_page_id = $org_options['event_page_id'];   

  $SQL = 'SELECT post_name  FROM wp_posts WHERE ID = %d';
  $event_page = $wpdb->get_var( $wpdb->prepare( $SQL, $event_page_id ));

  add_rewrite_rule( $event_page . '/([^/]+)?/$', 'index.php?pagename=' . $event_page . '&event_slug=$matches[1]', 'top' );
  add_rewrite_rule( $event_page . '/([^/]+)?$', 'index.php?pagename=' . $event_page . '&event_slug=$matches[1]', 'top' ); 

}
add_action( 'init', 'my_add_rewrite_rules' );

and this:

function add_query_vars( $query_vars ) {
  $query_vars[] = 'event_slug';
  return $query_vars;
}
add_filter( 'query_vars', 'add_query_vars' );   

the rewrite rules get flushed in the admin when the 'event_settings' options are updated.

I am using an amazing plugin by Jan Fabry called "Monkeyman Rewrite Analyzer" which can show you how your rewrite rules are being processed (check it out it's great).

This is the results from the above:

Test URL
    http://localhost/events/some-event

Pattern
    events/([^/]+)?$    

Substitution 
    pagename: events
    event_slug: some-event

also appears to work with an additional trailing slash:

Test URL
    http://localhost/events/some-event/

Pattern
    events/([^/]+)?/$   

Substitution 
    pagename: events
    event_slug: some-event

these results appear to be working properly, but when I enter "http://localhost/events/some-event" into my browser, it does not redirect as it should.

The resulting $_GET and $_REQUEST arrays are empty.

What am I doing wrong???

Any and all help is greatly appreciated, but correct answers will be appreciated more ; )

Thanks

share|improve this question
    
What $_GET or $_REQUEST args are you looking for? Once WP parses the URL and creates the query, you should be looking in $wp_query->query_vars instead ... –  EAMann Feb 1 '12 at 20:36
add comment

1 Answer

You can use the function get_query_var().

Like so:

$event_slug = get_query_var('event_slug');

More info in the Codex.

share|improve this answer
    
AHHHHH... That did it. Thank you so much. –  Brent Christensen Feb 1 '12 at 21:11
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.