I want to create an additional shorter Version of my Post-Permalink with a 301 redirect to the real post URL.
The shorter Version of the URL should get its Custom Field I added as a post meta. It is called $trick_nummer
So I have:
mydomain.com/%postname%/
additionally I want:
mydomain.com/Tipp%trick_nummer%
I think it should be something like that:
add_action("init", "tipp_rewrite_rule");
function tipp_rewrite_rule() {
add_rewrite_rule(
'^tipp([a-zA-Z0-9]+?)',
'index.php?$trick_nummer%',
'top'
);
}
For example:
mydomain.com/i-am-the-post-name
And the shorter Link (trick_nummer would be '7')
mydomain.com/Tipp7
with a 301 redirect to
mydomain.com/i-am-the-post-name
I found this Question: Redirect short-form URL to long-form URL (post_id to post_id + post_name) But the difference I want is, that I need the number from my custom field.
And I would like to do this in the functions.php
index.php?trick_nummer=7
which redirect to the good post. this can be done in the actionwp_loaded
with testing$_GET["trick_nummer"]
. – mmm Feb 24 '18 at 20:17