0

I am working on a plugin where I am trying to create a "archive like" page with permalinks.

Here is what I have so far:

  1. I've created a query var "experience"
  2. I've created custom SQL selects using - "post_join" and "post_where" hooks

  3. I've created a custom template using the "template_redirect" hook

  4. I've added custom permalink rules and flushed them

All good so far, the only thing I'm not getting is how I can link to my new archive like page "dynamically".

I can create a static link like mysite.com/experience/id - but this will not work when permalinks are off.

Also I tried to generate the URL like

<a href="' . add_query_arg( 'experience', $id, get_bloginfo('url') ) . '">url</a>

This works when permalinks ar off and also when on, but this not changes to mysite.com/experience/id when they are on. It always remain mysite.com/?experience=id

So what I would like to understand is how can I create those permalinks dynamically, so they will be recognized depending if permalinks are on/off.

Thank you.

1

Just write a function that checks if permalinks are on by checking whether get_option( 'permalink_structure' ) is empty or false and generates the appropriate link given the $id.

Something along the lines of the get_permalink() function which either looks at the $post global or looks at the $id passed into it.

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.