I’m not sure why you’re getting a 404, because when I run your code with permalinks = “Post name” it runs fine.
However, I would suggest you use remove_query_arg() instead of all the machinations you’re doing to produce the URL to redirect to. That is, you can simplify your code down to:
function
affiliate_redirect ()
{
$varname="affid" ;
$weeks="4" ;
if (isset ($_GET[$varname]) && '' != $_GET[$varname]) {
setcookie ('wp_affiliate', $_GET[$varname], time () + 648000 * $weeks, "https://wordpress.stackexchange.com/") ;
$url = remove_query_arg ($varname) ;
wp_redirect ($url) ;
exit ;
}
return ;
}
Try that and see if it doesn’t fix your 404 problem.
Related Posts:
- Hooking in to plugins
- How do I call wp_get_current_user() in a plugin when plugins are loaded before pluggable.php?
- Is there any sort of theme dependency management?
- Generate dormant hook references
- How to only hook on Single.php after content?
- What WordPress API function lists active/inactive plugins?
- How to stop showing admin notice after close button has been clicked
- How to save the values of checkbox to the register setting?
- Handling jQuery Component Collision
- why plugins are loaded prior to pluggables
- How to override normal WordPress search in Buddypress? [closed]
- Define Function in functions.php or plugin and call in theme loop
- How to get Login Error messages on a custom template
- Autogenerate wordpress shortcodes using array?
- Forum plugin that allows private groups that are invite only [closed]
- Why doesn’t the WordPress Importer update posts?
- Jetpack plugin (ShareDaddy): Prevent share buttons showing on custom post types?
- Enqueue style inside shortcode but its loaded at the bottom of page (before footer scripts)
- Creating button next to “add media” that allows you to choose a single post
- WooCommerce create new product and add to cart on form submit
- Extending WC_Cart in woocommerce
- dynamic page not indexed
- Add new password rule to Ultimate Member register form
- Claim Listing functionality – how to send email to users when their claim has been approved or denied
- How can I include PHP-Code to my post?
- Woocommerce exclude specific category products from related products [closed]
- Run Python Script on WordPress Website
- Ajax Load More and Masonry: is it possible to load admin-ajax.php in the front end?
- Seriously stuck with some custom meta box/plugin stuff
- explanation for activate_plugin function in wordpress core
- Does the ‘nav_menu_css_class’ filter accept 2 or 3 arguments?
- How many security plugins are too many? [closed]
- Get product attribute for Simple product in WooCommerce
- do_action and hook methods
- Developer plugin to echo template names/filepaths [closed]
- How do I get multiple pages by title?
- the_posts hook, which set of posts?
- Creating WordPress Plugin solely for Admin panel with dash menu and submenus
- I need to add a custom “cover” to every new post — plugin or custom setup?
- WordPress with CAS+LDAP and standard WP accounts
- Hosting plugin Google Code with auto update?
- Styling readme.html in plugin?
- Follow post plugins for WordPress
- How to prevent action in ajax request, when in admin side?
- Suspicious google tag manager
- How can I process xml file on upload?
- Permission Check for REST API Endpoint Runs Twice?
- Easy Digital Downloads (EDD) – Purchase Receipt emails couldn’t be logged
- Website dumps encoded result
- Remove obsolete plugins artifacts from database tables
- After activating a Plugin, /wp-admin is no longer accessible
- Does codex.wordpress.org use a plugin of some sort? If so what plugin?
- why shouldn’t i save metadata when its a revision
- Possible to add a language file to a plugin without adding .po/.mo files to plugin directory?
- Overriding Attributes values in Shortcode Plugins
- wordpress.org codebase
- Function to prevent users from trashing comments
- Can’t get plugin settings page to save data
- How to upload user profile image from frontend in wordpress ?
- How do you override the default comment template?
- Calling custom plugin class methods from a template
- How to import my YouTube channel into WordPress?
- Any Short code Availble for Get Post List With Thumbnail Plugin?
- problems with wordpress and php version 5.3.3-1
- My Category is too big on the Menu what can i do?
- How get a value from a plugin into another plugin through action/filter
- Carbon Fields use in custom plugin class
- WordPress takes too much time (100 seconds) to load – Front end and back end
- Integrating non-WooCommerce and WooCommerce Orders together [closed]
- Hook to plugins admin settings
- Fusion Slider Just keeps loading [closed]
- Exclude post by custom meta with pre_get_posts
- Media upload not working on theme option in WordPress 3.8.1
- how to change the verification url of pie register plugin of wordpress?
- (WooCommerce) Remove Sidebar only on Single-Product page
- Own plugin corrups plugin-activation
- CSV file generation failing
- How would I disable a plugin on one page?
- stack-overflow-like content ranking for wordpress?
- finding whether request is for post, and post id
- CSV syntax for WP All Import upload without ACF
- Error: Cannot find module ‘../build/Debug/nodegit.node’ [closed]
- How to fetch products with the price in a page on woocommerce using a form or live search with php
- Owl Carousel2 image not displaying full width when using Stretch row and content, Stretch row and content(no padding) in wordpress
- WpDataTables – View Image Directory
- Get Time Taken By Each Action Hook in WordPress
- Buddypress – Add the post_id in the bp_activity_add function
- WordPress site periodically goes down
- Server configuration for WordPress – Do I need install PHP-SSH extensions for WordPress on Fedora28?
- Masonry images not working
- How to block XML-RPC attack?
- How generate 200% image size and save with suffix @2x
- Automatic switch to backup database on fail
- Force language in translate function
- Display wordpress post’s in popup?
- How to remove custom post type and add category and post name
- wp_footer hook only working on homepage not in other pages
- Using color picker in plugin, does input attribute order matter?
- Can’t send mails wordpress using SMTP authenticate [closed]
- Some recent plugin updates have failed “Could not create directory”