0

I'm trying to update my link from this: https://dev.brunchwork.com/next-event/?eb_event_id=106098978902 To this: https://dev.brunchwork.com/next-event/[guest_name_here]/[event_id_here]

Following this discussion, I was able to come up with this code:

In my functions.php:

/*rewrite rule*/
function custom_rewrite_rule() {
    add_rewrite_rule('^next-event/([^/]*)/([^/]*)/?','index.php?page_id=69&guest_name=$matches[1]&event_id=$matches[2]','top');
}

add_action('init', 'custom_rewrite_rule', 10, 0);


add_filter('query_vars', 'add_query_vars');
function add_query_vars($aVars) {
    $aVars[] = "guest_name";
    $aVars[] = "event_id";
    return $aVars;
}
/*end rewrite rule*/

In my next-event page:

/*
Template Name: Single Event Template (updated)
*/

get_header();

global $wp_query;

$guest_name = $wp_query->query_vars['guest_name'];
$test_eb_event_id = $wp_query->query_vars['event_id'];

echo $guest_name;
echo $test_eb_event_id;

When I try to test the URL, the rewrite is not working. I also clicked the save button in the permalinks page to apply the changes.

So when I enter: https://dev.brunchwork.com/index.php?page_id=69&guest_name=test&event_id=123

I get https://dev.brunchwork.com/next-event/?guest_name=test&event_id=123

Any help is highly appreciated. Thank you very much!

0

There's nothing wrong with my code. Maybe it was not refreshed instantly so the changes did not propagate right away.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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