rewrite_rule for custom post type doesn’t affect get_permalink
rewrite_rule for custom post type doesn’t affect get_permalink
rewrite_rule for custom post type doesn’t affect get_permalink
Using ‘Primary Category’ in URL
It turns out that, I was using “year” as a custom taxonomy, which was part of the reserved terms of WordPress!!! With using the reserved term, it will return the 404 error for the top level pages, hence the redirection to the home page. !!! Listed here: https://codex.wordpress.org/Function_Reference/register_taxonomy#Reserved_Terms
Please place below code in your theme’s functions.php file & let me know how it goes 🙂 add_action(‘wp’, function(){ list($uri, $qs) = explode(‘?’, $_SERVER[‘REQUEST_URI’]); if ( $uri == “/arbitrary/path” ) /* Change this to path that you want to match*/ { locate_template( “template-full-width.php” , true, false ); /* Don’t forget to replace template name with … Read more
You could force the redirect this way by checking for the get_var query value: add_action(‘init’,’my_redirect_check’); function my_redirect_check() { if (isset($_GET[‘my_var’])) { if ($_GET[‘my_var’] != ”) { if ($_SERVER[“HTTPS”]) {$location = ‘https://’;} else {$location = ‘http://’;} $location .= $_SERVER[‘SERVER_NAME’]; $location .= strtok($_SERVER[‘REQUEST_URI’],’?’); $location = trailingslashit($location); $location .= $_GET[‘my_var’]; $location = trailingslashit($location); wp_redirect($location); exit; } } } … Read more
I’d check a few things Apache2 logs open a terminal Check error logs at tail -f /var/log/apache2/error_log Check access logs at tail -f /var/log/apache2/access_log WordPress Check .htaccess has correct rules for basic setup enable wp debugging to see if you can log further errors when the redirect happens this is how you enable WP logging … Read more
You’re close. Add the following to your .htaccess file in between the <IfModule mod_rewrite.c> tags that were created by WordPress: RewriteCond %{HTTP_HOST} RewriteRule ^(.+)-[0-9]+/$ /$1 [R=301] Your .htaccess should looks like the following if it hasn’t been modified by another plugin: # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ – [L] RewriteCond … Read more
You could try using the add_rewrite_endpoint function, which would actually let you avoid any htaccess modification (unless you need $_GET). Example: function add_custom_rewrite_ep() { add_rewrite_endpoint(‘cata’, EP_PAGES); add_rewrite_endpoint(‘catb’, EP_PAGES); add_rewrite_endpoint(‘catc’, EP_PAGES); } add_action( ‘init’, ‘add_custom_rewrite_ep’ ); Make sure you flush your rewrite rules. So then, if your URL is /questions/cata/foo/catb/bar/catc/more/, you can access the values with … Read more
After hours of searching and reading, This is how I solved the Problem. Step 1: Create a .htaccess file in the root folder and put this code there. # BEGIN <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ – [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END Step 2: … Read more
Wow I feel like a huge newblet. This is incredibly simple. Just escape it with a \. “&feed=$matches[1]” should be “&feed=\$matches[1]”. EASY.