Custom post type slug duplicates - wordpress

I purchased a plugin that allows buddypress users to add new pages to their profile and ran into an issue that caused me to reach out to the developers, only to realize that this seems to be an issue with every custom post type, and is not isolated to a single plugin. This very well may be a Wordpress thing, but this is extremely inconvenient and I was wondering if there was a way around this.
When users add new pages to their profile, even if the permalink is unique, on the chance that a user names their page the same name as another user, a number denoting a duplicate is added to the permalink.
For example:
User 1 makes a page titled Services (mysite.com/user1/services
User 2 also makes a page titled Services (mysite.com/user2/services-2)
I have changed the post type permalink to include /%author%/%post-name% which works correctly, and changes the permalink, except a number is still added to the end if more than one page has the same title. How can I stop this from happening if the pages are made by different authors?
This was the message I sent to the developers of the plugin, who informed me the issue isn’t really the permalinks, it’s more that the pages are a custom post type and thus beholden to the same slug rules that normal pages have, where if you created 2 pages named “contact”, the second one gets “contact-2” and so on.
I had assumed the user’s buddypress/author page would count as a parent page, but it seems that’s not the case. This appears to occur on my own custom post types as well as any custom post type plugin I happen to use, but I had never tested that until just now. Even if the permalink itself is unique, custom post types cannot have the same title/slug even if created by different users and I can see this hindering user experience.
Does anyone have any thoughts?

Adding author to permalink does not make the page unique. Pages are defined as individual objects and their permalinks are related only to the last section of the link.
The system compares only the post name (the slug) not the full URL or permalink.
mysite.com/user1/{post_slug}
If the {post_slug} is the same as another post slug then the system adds incrementation.
Just to clarify the answer - The post permalink is defined by the post slug and not the permalink itself.
What I would do in your case is to set these pages to an ID-based permalink.

Related

Is it possible to automatically add a slug to an already existing URL once permalink structure has been changed?

I am running a website in which the different posts all have an associated category: let's say, news, reviews, videos, etc.. We want to change how URLs are generated to incorporate the category before postname.
I will put an example:
old url: https:///www.myweb.com/amazing-new-car (with category in the post being news)
new url: https:///www.myweb.com/news/amazing-new-car (with category in the post being news)
I know how to do this by changing permalink structure in the wordpress settings to /%category%/%postname%/ but the problem is that this is applied to older entries too so when i try to access https:///www.myweb.com/amazing-new-car it gives me a 404 error. The problem here is that we have links to parts of our site sent to people, social networks and so and if they use them they will see this 404 error.
I've tried to use Redirection plugin to create a rule that can redirect old URLs to new URLs but it does not work (i've tried even wildcard redirection).
My question is: is there any way to do what i want rather than individual renaming of the links?
Thanks in advance, i hope i've explained well my problem
WordPress has all the tools necessary to make this change happen, and typically it does successfully redirect the slug from /slug to /news/slug
If you have added a category and haven't touched permalink settings, this is probably your problem.
Once you add a new category or post type into Wordpress, you should go into the Permalink settings and just click save. No need to change the settings if you are happy with them...

Permalink Goes to Old Page

I have been working on a site created by another developer. I have been fixing the site to make it more visually appealing. I am also responsible for adding new events and pictures which i self taught myself to do.
I have a situation where I have a page with the following permalink:
http://www.cic-nj.org/events/
The problem is that this link goes to a page that does not show the edits that i am making under that page and there is no other page listed that shows the info it actually displays.
this is what I have in the editor box on wordpress that I want it to show.
enter image description here
this is what appears when url is used or when i click view
enter image description here
I have been sure to click update and renewing page to view it. it's like its going to a ghost page i can not edit.
Can anyone point me in the right direction on this?
Thanks in advance...
You are experiencing "slug collision": more than one thing in your WP install has the same slug.
The problem that you have is events is a custom post type, with a slug set to events - therefore the url http://www.cic-nj.org/events/ is directing to the listing of events. This is an automatic feature of WordPress. (Note - you can see more details to support this conclusion by the fact that you've got individual events accessible at url's such as http://www.cic-nj.org/events/blue-apron-info-session/ )
Note that custom post type slugs will always take priority over a page / post slug.
You have a couple of options:
If you want a page to display the content that you've created, the page's slug / permalink must be different than events
If it's acceptable, you can rename the slug of the "events" custom post type to something different. This has the potential consequence of losing SEO "juice".
If it's acceptable, you can remove the custom post type, if you aren't going to use them any longer.
NOTE: It may be tempting to ask "how do I remove the custom post type", or "how do I change the post type slug". Those are different questions, and if you need to ask, they should be asked in a different question - not added as a comment below.

Set the permalink to any domain in Wordpress

Is this possible to achieve without too much effort or a plugin? It's simply to instantly redirect to a site I've made in my portfolio if the post doesn't have any content.
Note that I don't want a script in the actual post to redirect since I only use Wordpress as the backend and fetch all the data to be used by a JavaScript backbone app.
EDIT : Added some extra info in a comment
Short Answer: No. You cannot set your Post Permalink to an external asset without directly editing the database.
Long Answer: First off, you need to understand the purpose of the Permalink. It isn't just an arbitrary link to somewhere. It's reserved specifically for storing where that specific post lives within the context of your Wordpress installation.
Your post doesn't live on example.com. It has its own ID, and Wordpress has a specific spot set aside for it where it can be seen on YOUR domain. Leave it as such.
Instead, what you should be doing is employing the tools Wordpress gives you to achieve what you want. A Plugin doesn't exist for what you want because - quite frankly - it's a fairly trivial task when approached CORRECTLY and doesn't warrant the use of an external resource.
So what's the correct way?
Use a Custom Field. Name your Custom Field something like 'externalHref' and fill that in with your link to the website you want to point to in case there's no post content.
Then in whatever templates you're using to generate your posts, just check either for the existence of your Custom Field called 'externalHref' or check for the non-existence of Post Content. In either case, instead of generating a link using The Permalink you can simply build a link that points to wherever you need.

Post privacy in Wordpress

Can a post be hidden from home page, archive view, category lists etc. and viewable only if you have a direct link to it? The blog doesn't have registered readers and is open to public so that would be a mean of hiding some posts from public view without using the password protection.
I asked this question in Wordpress section and the idea there was to use conditional code so I'm asking the question here as well to get closer to the code.
If I used conditioning, would I have to input each post's ID separately to PHP file for archive, categories, search and such?
EDIT:
After reading a bit more all over, I had an idea of creating a private category and then use some kind of conditioning so that posts from that category are hidden. According to Codex, certain category can be hidden from, for example front page but I don't know if there's a way to hide it altogether except when you have a direct link.
Creating a "Private" category is a good solution. It is quite possible to hide this category altogether except via direct link. You just have to "block all the exits" with conditional code.
The default WordPress theme displays posts via the Post Loop. See http://codex.wordpress.org/The_Loop, especially the section entitled "Exclude Posts from Some Category". Just find all the places in your theme's PHP files (e.g. index.php) where this loop is used, and add the conditional code. You'd also need to filter your category list and blog archives in the side menu. Don't add filtering in single.php, otherwise the private post won't display on its own page.
You'd probably want to add a similar condition to filter search results so that private posts aren't leaked via the blog's search tool. There may be more "exits" I haven't thought of, but I'll be sure to update as I do. I'm glad to look at specific code if you so desire.
Understanding WordPress' post query and loop really opens up a world of possibilities for customization.
I found the simplest way - just use Simply Exclude Wordpress plugin. It has the option to exclude each post (or tag, for that matter) from front page, archive, search or feed. It works flawlessly. You can still view the posts by using direct links.
(Not actually an answer that includes code but a working solution nonetheless.)

Building a "lecture notes" website with wordpress

I wish to build a "lecture notes" website using wordpress. And would love for any advice on what plugins to use, other considerations to have or website that perform a similar task with WP.
The website should have a form that will allow users to upload their lecture files. The results should be a new "post". When submitting the form, the users should be able to tag their subject matter so to allow others to search it.
I would search for a "Members" type plugin, that lets you really fine-tune the roles and capabilities of each user type. Then you can let your users sign up as "contributor" or other lower level, and then use the Posts as your notes pages. Each post would have the ability to upload a file (not sure what formats are accepted, you might need a doc/pdf type plugin for that). You could also narrow it down by pre-specifying categories. Then you could use the comments as a discussion forum for each "lecture". Depending on the depth of customization you wanted, this could be fairly easy, or extremely complicated. ;)
If the WordPress site is on wordpress.com, then you can set the site so that you can publish via email. You might create a separate category for each person that is going to post to the site. There are "shortcodes" (see WordPress Support page "post-by-email" below for a list) which can be added to each email that will direct that post to one or more categories [one category might distinguish the poster, while other categories might group postings by topics, etc.]. Another shortcode can make the posting a "draft" or "private", while I think the default is to make the posting live immediately. *If you post by email, then all posters do not have to have Admin access to the site, they just have to have the unique WP site email posting address. *If you want to try the "Audio Post" feature (call from any phone and enter unique WP site key code), I don't think there is a way for the caller to direct the audio posts to a category via the call. An admin would have to add the category to any audio posts later. **All WP site "categories" automatically have an RSS feed created for them, so each of your posters would have their own chronological list of postings.
http://en.support.wordpress.com/post-by-email/

Resources