Alright, so I found the solution, it was a simple change in the request object class variable:
function redirect_workaround( $request ){
if( $request->request === 'myspecialurl' ) {
$latest = new WP_Query( array(
'category_name' => 'myspecialcategory',
'posts_per_page' => 1
) );
if( $latest->have_posts() ){
wp_redirect( get_permalink( $latest->post->ID ) );
exit;
}
}
}
add_action( 'parse_request', 'redirect_workaround' );
Related Posts:
- How to redirect non-logged in users to a specific page?
- When I change slug, will WordPress create redirect from the old URL?
- Why am I getting a 301 on a existing post?
- Keeps on redirecting on my development copy
- Password change when the user login first time
- Custom login form redirect to external site
- Clarification on auth_redirect()
- Redirect to custom url when registration fails?
- Exclude a path from WordPress using .htaccess redirects (Apache)
- Best way to handle redirects
- Redirect to custom URL after registering from a page with registration form
- Stop unwanted WP redirection to new url
- Problem to redirect custom page using htaccess
- WordPress Customizer: custom redirection after closing
- Website redirecting to old domain name
- How to do 301 redirect to Sub page using htaccess file?
- Hiding WordPress behind IIS redirects
- Redirect guest if he tries to access a specific page
- htaccess 301 redirect http to https doesn’t work
- Site redirecting from http to https [closed]
- Use htaccess to redirect WordPress to static website in a subfolder
- Defining a custom 404 for non-WordPress parts of site
- Redirect homepage ( www.sitename.com ) to the latest post
- Redirect from sub-directory to root – New WordPress 5.2.3 Set up
- How to redirect URL with subfolder to the same URL but without subfolder?
- Site loads very slowly (4-5 minute load time)
- If User is NOT Logged in and Page ID is not 6 – Redirect to Login
- Snippet for own (gr)avatars
- Front end user creation form! How do you keep the user on the same page in event of error?
- 503 Service Unavailable error was encountered
- SSL and www to non-www redirection works only on homepage – WordPress
- How to redirect if a background request is still being executed
- Page template that redirects user based on role
- How can i resolve 301 redirection Issue on my website?
- WordPress keeps redirecting subpages without http to https homepage after switch
- Redirect non-existent subpages to second part of url
- How to remove the [L] Flag for WordPress index .php mod_rewrite
- ReDirect subfolder link to another sub-folder and force SSL
- How do I remove the RSS Feed Redirect?
- Two WordPress installations: One in root and one in sub directory – no images in subdir installation [closed]
- Redirect user to original url after login?
- User redirect to specific URL after logging in
- A WordPress site with more than one domain name / Parked domains
- Redirect user if they are not logged in
- BuddyPress – Redirects on Login and Logout
- How to redirect a wrong search on my wordpress website to the error 404 page?
- store URL global before we redirect
- Redirect to page for KPI/marketing purpouses
- Will deleting WP’s code in .htaccess cause problems?
- adding GET variables to a header() location in a page template
- Migrating to Tumblr [closed]
- Parked domain redirect
- WordPress CSS/Theme gone after SSL got activated
- How to fix automatic redirects?
- Redirecting DNS without breaking everything
- How to redirect non existent pages/posts in wordpress using htaccess
- redirect doesn’t work while using example code
- How to redirect all page requests to a single “goodbye” homepage? [duplicate]
- Endless Redirects Suddenly Disable Site
- Redirecting home to /wp-login.php?action=register
- How to redirect a child page to its parent page?
- 301 redirect after removing language directories
- wp_login_form() redirect same page
- Redirect user after login to prior page through a wp_login hook
- Redirect *.php to path using web.config file
- How can force redirected to login for two or more pages to view or access
- WordPress not linking correctly with .htaccess redirect to subdirectory
- Auto redirect to different web page
- WordPress installed on a virtual machine and behind a reverse proxy is redirecting to the VM’s IP address
- Login redirects to home page and doesn’t log in
- wp_redirect() not redirecting user to supplied URL
- How to redirect?
- How to disable WordPress URL autocomplete / recognition?
- using wp_rewrite but keep the original url in the address bar
- Some links keeps redirecting to another domain
- Redirect every link that starts with
- login redirect problem – db charset issue?
- Custom login-form redirect
- Link to another website with the same url path
- Redirect to Page after Login (with variable)
- I have cloudflare flexible enabled, How to redirect to https for Nginx server
- .htaccess not working after page slug change
- can’t handle a redirect
- How can public access to WordPress query (e.g. author=) URLs be redirected?
- Wrong Redirection
- WordPress HTTPS – ‘… better to use HTTP for installation …’
- Rewrite rule for incoming urls
- Detect if request is coming from wordpress conditional statement
- WordPress on a subfolder but accessible from root
- Can I redirect the http request towards an old folder to the homepage using .htaccess file? [closed]
- Facebook redirect buton
- How do make WordPress to let alone my static home page?
- how to get my WP site’s IP? [closed]
- How to redirect users without permission to view content to a custom page?
- redirect the root of a domain, while leaving the www version unredirected
- How to Create Custom Route to a page in WordPress
- How to create a redirect to another domain like safe redirect manager from php
- Post Migration Site Migration Redirects All Known Solutions Attempted
- When invalid child page entered, WP redirects to next available page instead of giving Page Not Found
- Redirect non-logged in users to a specific page