wordpress custom post type - wordpress

So I've just made a custom post type for my wordpress theme named "Products". When I create a new post in it and view it, the link is something like this:
"http://localhost/wordpress/product/a-product-title"
This page views as expected but when I try to go to the supposed parent page:
"http://localhost/wordpress/product/"
I get a 404 error page. Is there a special template I need to make to view this page?
Thanks

I found what to do. I just created a new page called "Products" and set it as the posts page. Then I put this in front of the loop
$wp_query = new WP_Query("post_type=product");
and it worked

I had the same issue - I think it's down to the fact that right now, WP 3.0 simply does not behave as you would expect with custom post type 'archives'.
Check out Smarter Custom Posts to easily build-in this behaviour.

The name Products is also used by Woocommerce so be aware that if you install this too, the custom post type will stop working.

Related

How to create Wordpress' permalinks after creating a custom post type?

I just created a custom post type called products in Wordpress. When I select plain permalinks, the links work fine. When I select any other permalink, the URL cannot be found.
For instance, http://localhost/TheGrind/?products=gopro-hero6-black is my permalink with the plain option selected. And http://localhost/TheGrind/product/gopro-hero6-black/is the permalink that I'm looking to use for my posts. I get a
Not Found
The requested URL /TheGrind/product/gopro-hero6-black/ was not found on this server.
The question is how can I get this type of URL to work when I create a custom post type in Wordpress.
Any help is greatly appreciated.
You could try adding
flush_rewrite_rules();
after you have called
register_post_type();
That has fixed the issue for me in the past.
If it does work for you, you can then remove the "flush_rewrite_rules();" as WordPress states it is an expensive operation.
https://codex.wordpress.org/Function_Reference/flush_rewrite_rules

Parent permalink slug before CPT slug

I'm currently busy making a FAQ for my website but i'm struggling with the permalink structure.
I have made a regular page where people can see an overview of the FAQs. I called that page Klantadvies.
I installed a Custom Post Type plugin and made a post type called faq. I also made a taxonomy which is called onderwerp.
Unfortunately the plugin won't allow me to have a page parent in the slug. So i'm wondering if it's possible to have my page slug (klantadvies) in front of the custom post type slug. For example:
http://mypage.com/klantadvies/faq/onderwerp
Thnx in advance!
Rather than using a plugin for your post types and taxonomies, I'd recommend you use these two solutions:
https://generatewp.com/post-type/
https://generatewp.com/taxonomy/
You can use those to create your Post Type and Taxonomies. Within each of those configs you're allowed to setup the slugs / URL structure that you want to use.
On top of that you're going to need to setup a custom rewrite rule to handle echoing out the values you're looking for on the appropriate layout.
https://codex.wordpress.org/Rewrite_API/add_rewrite_rule

generate custom permalink based on a custom field - Wordpress

I'm a newbie to the Wordpress.
So far I have a custom post type called 'property'. This post type has one custom field called 'property_city'.
In WP-admin - permalink setting, I have selected Post name option. So, posts of this custom post type have URLs like:
http://xxx.local/properties/edge-apartments/
http://xxx.local/properties/northgate-point/
What I want to have those URL to be generated using the city of the property and also I want to change properties prefix with student-properties like that:
http://xxx.local/student-properties/Manchester/edge-apartments/
http://xxx.local/student-properties/Chester/northgate-point/
I have tried various plugin and various code, but none of them worked as expected.
Any help would be appreciated.
Thanks,
try Permalink manager plugin it works for me here is the link : https://wordpress.org/plugins/permalink-manager/

Need to clone a existing wordpress admin page

I need to create a new page which will have same functionality of one the page of admin.
I have a page which is accessed by /wp-admin/post-new.php?post_type=shop_order.
I have made a copy of this page by the name "new-post0.php" but when I access new cloned page , its content is different!
I m missing something at registering this new page?
You shouldn't copy and paste Wordpress core files. That's called "hacking the core" which is very very bad.
http://websynthesis.com/dont-hack-wordpress-core/
You should instead develop your "new-post" page as a new custom post type.
You can learn about them here:
http://codex.wordpress.org/Post_Types
The link /wp-admin/post-new.php?post_type=shop_order you posted refers to a new post page for a custom post type.
To get another page like that, you'll need to create another custom post type and add the custom meta fields.
If you can't code it, there are plugins that you can use to achieve the same results.
Custom Post Type UI to create custom post types and ACF for custom fields. Right now, you should download ACF from Github.

Wordpress custom post type page

When creating a custom post type and fill it with some posts wordpress generates a page for that custom post type.
But I want to be able to add content to that page so I create a regular page and choose a template where I manually call the custom post type posts and loop them out. And now I can just add content in the wysiwyg editor. But this causes a conflict between these two pages, especially if the CPT has the same name as the page.
And now the question: Is there a way to always show the page where I have chosen the template for the CPT to always show? Even when someone try's to manually enter the url for the CPT generated page?
Here is what I understood from your question. You have custom post type. Then you created a page-template, that loops through your custom post types and output them. Now when you create a new page and assign it the page-template you have created you run into problems, if it has the same name as the custom post type.
Solution: I think what you need to do is change the custom-page slug from the admin menu. Then you would be able to directly reference it by the URL.

Resources