Redirect to wordpress page without page ID

558 views Asked by At

I'm looking for a way to redirect to a specific wordpress page without knowing the ID.

I have a shortcode that is meant to redirect to a registration page once a button is clicked.

Before, I was able to just use a page ID. Now I am using WPML and the page ID's are all different for each language.

How can I redirect to a specific wordpress page without knowing the specific page ID for the current language?

2

There are 2 answers

2
brasofilo On

Maybe you could use get_page_by_path() or get_page_by_title().

Both functions accept Post Type as argument, it's not only restricted to "pages". And they will return a full $post object, ie, $post->ID.

Maybe a WPML function is needed, an equivalent of those. Or maybe a combination.
See the docs for Language dependent IDs.

1
probablyup On

You could add a custom field which will be shared by all versions of the same article, and then query by that instead. Something like an article GUID.