unexpected custom posts redirections in WordPress - wordpress

I have a plugin which creates custom post types and permalinks of these custom posts are like these:
https://www.example.com/my-custom-post-type/sample-1
https://www.example.com/my-custom-post-type/sample-1/child-1
https://www.example.com/my-custom-post-type/sample-2
https://www.example.com/my-custom-post-type/sample-2/child-1
When I am in WordPress admin and click on display, I can see any of these custom post types correctly, and their permalinks are fine.
When I am a visitor on the front end, I have clickable items which triggers redirections such as:
window.location.href = https://www.example.com/my-custom-post-type/sample-2/child-1;
The problem is that when I click on that link, the post displayed is:
https://www.example.com/my-custom-post-type/sample-1/child-1;
i.e. child slug is fine but parent slug is wrong.
Even stranger, when I enter in the browser address bar a URL which does not exist, such as:
https://www.example.com/my-custom-post-type/dummy-parent/child-1;
WordPress displays
https://www.example.com/my-custom-post-type/sample-1/child-1;
I have already flushed permalinks and it does not solve these issues.
Any help appreciated, such as how to diagnose where things go wrong.

Related

Postname permalinks not working – all pages send to homepage

I have WordPress installed in a subfolder of my domain. I want to keep it there, so that it is accessible only through http://www.example.com/mywordpress.
I have an issue with permalinks. If I use postname permalinks, all my pages (with different templates applied) redirect to the homepage, while my archives (including custom post type archives and singles) are displaying correctly. If I use custom structure permalinks and I prepend anything to the postname – for example /test/%postname%/ – all pages display correctly while custom post type archives and singles display a 404 error.
This happens whenever I refresh permalinks and also after replacing .htaccess with one from a brand new WP install.
The odd thing is also how the permalinks are displaying in the browser url field:
if I use /%postname%/
pages (not working) display as
http://www.example.com/mywordpress/postname – they all display the
homepage contents
CPT archives+singles (working) display as
http://www.example.com/mywordpress/postname
if I use /test/%postname%/
pages (working) display as
http://www.example.com/mywordpress/postname – so without the
prepended text!
CPT archives+singles (not working) display as
http://www.example.com/mywordpress/test/postname – displaying a 404
error
My custom post types have slugs translated to different languages with WPML. I thought that might cause the issue, however I tried to deactivate all plugins included WPML and still no luck.
Does anyone know what might cause that?
I figured it out. I was using reserved terms as custom taxonomy slugs (https://codex.wordpress.org/Reserved_Terms). By changing them to something else everything started working normally again!

Wordpress - /page/2 not working but /?paged=2 is

I have a WordPress site where my front page is showing the latest posts.
If I have my permalinks set as plain showing...
https://example.com/paged?=2
The page loads. However, If I change the permalinks to Post name, giving me...
https://example.com/page/2/
That results in a 404.
.htaccess seems to be set up correctly. The first page has posts and the links are being generated in the pagination controls. Using Post name as the permalink setting my posts are properly linked...
https://example.com/my-wordpress-post
But https://example.com/page/2/ does not work.
Any ideas? I really need to set the permalinks to Post name. Could it be a server issue?
First thing I would recommend is to confirm your .htaccess file is set up correctly to process permalinks. If you create a new page, can you access that page with his human-friendly permalink, for example? If not, you may need to fix your .htaccess file to handle those rewrites properly.
Otherwise, can you provide more context for this issue? Is it safe to assume you have your homepage set up with a list of paginated posts?
I figured this out. Instead of selecting Post Name, I select the Custom Structure radio button instead and manually added /%postname%/ and then clicked saved.
Then it worked. :)

Changing a permalink in wordpress?

I have a post in wordpress. I changed its permalink. Previously it was:
http://example.com/foo/dogs-so-awesome/
and I change the permalink to:
http://example.com/foo/dogs/
I was expecting the old url to no longer work, but I can still hit it from a web browser and see the page. The new url works, too. Is wordpress doing a redirect here? I'd actually like to remove the old url so it 404s when someone tries to hit it. But I can't find anything in the wordpress admin interface that suggests how to do that.
Thanks
Did you change the title of the page? or the permalink?
If you changed the "title" of it, then the page will be titled dogs, but the permalink will still be dogs-so-awesome. Just underneath the title is the permalink with an "Edit Permalink" option. Use that.
If you want to 404 it, you could use something (possibly the Page Links To plugin) and create a post at dogs-so-awesome and 404 it.

wordpress "Pages" permalinks not working, all redirect to homepage

My wordpress site is acting weird. The problem is like this:
The page www.mysite.com/about-us is not showing, but showing the homepage content.
Also when you type some not exiting pages like www.mysite.com/abcdef also show the homepage, not a 404 error.
(I am using the link structure /%category%/%postname%.html. and a plugin called no parent categories which removes the parent categories from the link.)
I tried to set the link structure to default and disable the plugin, still no use.
can anybody kindly help?

.htaccess issue in Wordpress giving 404 on all pages

I have a wordpress multi-site:
site1.local.loc [with subdomains on my local] and I would like to have three pages on this.
site1.local.loc/works - (posts page, but I want 'Works' as my title)
site1.local.loc/about - (static page)
site1.local.loc/contact - (static page)
Since 'Works' is my posts page where I keep putting in content, I changed my permalinks for this site to:
/works/%postname%/
However, when clicking on 'view post' at the end of posting anything, it leads me to a '404' page which means there is a disconnect. This is also the case for viewing any page. Is my .htaccess file faulty?
How do I solve this? Also how do I make all my posts appear in my 'Works' page (as in, how to make that page the posts page?)
Thanks!
Updated: I've found out that I get a 404 for any page that I create for a site in a wordpress network.
You do not have to touch .htaccess file.
Make a custom post type that is called works. All those posts made in that custom post type will have that url that you desire. There is no other way to do it. (even if there is, it must be dirty) That is celanest way, and since wp does it by itself you can expect that nothing will go wrong wnen you update, install plugins, etc.
Create a category called "Works" that would then show all posts added to that category by simply going to /works/ all posts would then be shown as /works/post-name/.
You will need to change the permalink structure to /%category%/%postname%/
Check this in administration
Settings > Permalinks > Post name

Resources