here is an idea, first add lid
to query_vars:
add_filter('query_vars', 'lid_query_vars');
function lid_query_vars($vars) {
// add lid to the valid list of variables
$new_vars = array('lid');
$vars = $new_vars + $vars;
return $vars;
}
then use parse_request
hook to create your redirect
add_action('parse_request', 'lid_parse_request');
function lid_parse_request($wp) {
// only process requests with "lid"
if (array_key_exists('lid', $wp->query_vars) && $wp->query_vars['lid'] != '') {
$args = array('meta_key' => 'lid', 'meta_value' => $wp->query_vars['lid']);
$redirect_to_post = get_posts($args);
foreach($redirect_to_post as $p){
$link = get_permalink($p->ID);
wp_redirect( $link , 301 );
exit;
}
}
}
Related Posts:
- How does WordPress handle permalinks?
- Auto 301 to full post permalink? (using /posts/%post_id%/%postname%)
- Random Alphanumeric Key URLs
- Using WP rather than .htaccess to redirect pages/posts
- Redirect a Blogger Page URL to wordpress
- Passing the JQuery string to Worldpress URL
- Visiting posts results in 404 errors after host migration
- Redirecting “wrong” but working links to their canonical URL in order to prevent search engine penalties (e.g. /123/ at the end of URLs)
- After cloning WP do a subdirectory, I can’t access it
- Custom permalink structure with %postname% in front of domain name
- corrupted URLs – can’t leave starting page
- remove SLASH on single_post but KEEP on categories and parent pages
- All pages lead to home
- WordPress permalink still not working (error or not understood?)
- My wordpress site must be being affected by outside sources [duplicate]
- Creating custom permalink structure for languages
- How to add a custom URL placeholder to author archives?
- 301 Redirects for Changed Permalink Structure & Category Base
- permastruct for custom post type not working in one of four cases
- Remove parent slug for child pages
- Nice RSS Feed URLs for each custom post type
- Change the custom post type permalink
- Rewrite url / permalink for default archive – yearly / monthly
- WordPress on VirtualBox – no pretty permalinks
- Permalinks, Rewrites, Get Variables, Oh My!
- How to Modify Existing Rewrite Rules?
- Top level Pages redirecting to homepage!
- Image Attachment Url Rewrite
- Specific URL Rewriting with parameters in wordpress
- Rewrite Page with a slug before page name
- Can’t get rewrite rules working
- Rewrite my default post URL
- When is it a good idea to build a permalink structure from scratch?
- If the only permalink setting is %postname% what happens in the case of old duplicates?
- How to reset canonical URLs / fix redirect loop
- Permalinks: Page Not Found
- Post incorrectly displaying as page
- why does my url not update after migration?
- remove sub-category of Custom Post Type from permalink structure
- WordPress Permalinks & Nginx Rewrite Rule Not Working
- Point domain to different webhost’s subdirectory wordpress
- Is a permastruct possible on pages?
- Changing the post date without causing 404 error
- Rewrite rule for a query string
- WPML – how to get the permalinks to display also the default language
- Need to add trailing slash to all internal links relative and absolute
- How to rewrite a URL to another rewritten URL without changing the address?
- How to use different domains for different blogs hosted in the same host in subdomains with .htaccess
- How can I make internal anchor links work with WordPress’s permalinks?
- How can I emulate permalink behaviour on static pages
- wordpress how to replace url /bar with foo/bar for custom post type
- Media/attachment urls don’t redirect with fake URL structure
- Test site pages go to main site
- Getting back a permalink from custom url
- Permalinks on Windows IIS not working and web.config breaks site – does wordpress not support windows server now, if so how?
- I’ve removed my /author/ slug but it clashes with new and existing pages. Any fixes?
- Exclude single page from permalink rule
- Bulk append URL (add word to slug)
- How are WordPress Page URLs affected by permalink settings?
- WordPress pages and posts are redirecting to server IP address instead of domain URL [closed]
- Rewrite rule not passing variable
- Passing variable as permalink URL
- Access posts while mod_rewrite is broken
- “set_front” => false on custom post type breaks wp_list_categories links [closed]
- All pages load the home page if pretty permalinks are used
- Make the blog page a child of another page and rewrite the blog url
- where can i see wordpress automatic redirect History
- WordPress keeps removing query var from the URL
- How to construct a dynamic rewrite rule for child pages that passes more than one query var
- Extending page urls without getting a 404
- How can I access to the same post-type “page” from multiple different urls?
- Multiple URL rewrite rules and get every prams
- How to separate an overgrown blog into sub-blogs – without breaking existing inbound links?
- Using a template file for a specific custom URL
- Pretty Permalinks with CTP and Taxonomies / Hierarchical
- How to experiment with permalink structure on a select number of posts
- append current user-id to all internal permalinks
- rebuilding/ rewriting a url to make it SEO friendly
- No Ones Been Able to Override my WordPress Rewrite Rule Issue!
- My permalinks for all pages and posts now include old page titles as parents/categories
- Pagination links for taxonomy archive page 404 error on every page except first
- Changed Permalinks settings, how do I redirect posts on Nginx?
- WordPress Pagination Custom Rewrite Rule for Pages
- WordPress Category url redirects to subdomain
- Change all pages permalinks instead of hierarchical to have id of the page
- Links after changing hosting and domain
- rewrites and custom links in page need help with add_rewrite_rule
- Category-dependent custom permalink
- How to create an IIS7 re-write rule for a single category
- Although rewrite engine is on, I get 404 not found on every page
- Customized author slugs not working with get_author_posts_url method
- Remove index.php from WP 8.0 install migrated to IIS from Apache (still detecting Apache server)?
- ?posts_type=xxx not rewritten
- region selection
- Redirecting From An Old Permalink Structure
- WordPress custom permalinks, pages are now 404
- Include language variable in url
- Creating complex URLs with WordPress permalink structure
- Add additional URL variations for a Post
- How to make my custom permalink pull up the correct post