0

I'm developing an calender. It works very well for. My last point on the list is "make the url pretty".

Currently I have a page (example.com/my-calendar/) with a custom php-template which renders the calender sheet. It is displayed only one month per page. By a $_GET parameter I'm displaying the right sheet.

That means the URL example.com/my-calendar/?base_date=05-2017 displayes me the calendar sheet for may 2017. But I wanted to have the URL like:

example.com/my-calendar/05-2017

or

example.com/my-calendar/may-2017

I'm playing around with this tutorial but did'nt get it work.

  • Why not example.com/my-calendar/2017-05 ? – prosti Jan 5 '17 at 17:56
  • The tutorial you linked has everything you'd need to accomplish what you're doing. Which part 'didn't work'? – iguanarama Jan 5 '17 at 18:08
  • @iguanarama I added a new comment with my current code :) – snuwie Jan 5 '17 at 21:08
  • @prosti the value is not my problem. I want to know how to pass a parameter by rewrite rule. – snuwie Jan 5 '17 at 21:08
0

Here is my current code:

function hm_base_date_query_vars($vars) {
    $vars[] = 'base_date';

    return $vars;
}
add_filter('query_vars', 'hm_base_date_query_vars');

function hm_base_date_rewrite_rule() {
    add_rewrite_rule(
        '^my-calendar/([^/]*)/?',
        'index.php?pagename=my-calendar&base_date=$matches[1]',
        'top'
    );
}
add_action('init', 'hm_base_date_rewrite_rule', 10, 0);

$base_date_test = get_query_var('base_date');

on the url example.com/my-calendar/foo my var $base_date_test returns null

Maybe someone can help me. Thanks.

// Edit: It works. I tried to call the var in functions.php but I had to call it in my custom php template -.-

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.