Post Types, Taxonomies and routing - wordpress

I'm ready to give up on Wordpress.
I've got this issue. I have created a custom post-type via wp-types plugin. I can display it and display posts from it.
However, I have created a custom page with a custom template that renders the posts. I have done so because the site uses multiple languages, and I needed the url to be in that specific language.
Thus the post-type is not displayed through the standard archive-{post-type-name}.php file, but instead a custom template and a custom wordpress page.
Just because I need the urls to be in the same language as the given page language, example:
myurl.com/{name_in_one_language}
and
myurl.com/{name_in_another_language}
The issue with that is that my custom post-type has custom taxonomies attached to it. Before the posts are rendered I select the taxonomy and then render the rest of the page based on the taxonomy name. Example:
myurl.com/paintings/?category=category_name
|| or ||
myurl.com/paintings/?author=painting_author
The thing is that the client doesn't like that kind of custom url parameters. He is begging for me to change it to the following format:
myurl.com/paintings/{taxonomy}/{painting}
Where taxonomy is either authors name or art type. And the paintings page itself is just a middleware to select which post with the needed taxonomy needs to be displayed.
I have ran out of ideas of how to do it. Completely.
I tried going with the archive-{post-type-name}.php solution, have no clue how wp-types plugin rewrite works. Tried using the wordpress permalink syntax in the plugin, doesn't recognize it.
Basically what I need is the following: For my custom page that has a custom template that renders custom post-type with custom taxonomies to route in the following way:
myurl.com/{page-with-template-that-renders-custom-post-type}/{post-type-taxonomy}/{post}
I really find Wordpress difficult to work with, the way you have to inject code, handle routes, register types. It feels like you're just patching it together to make a horrible monster that spews code bile over everyone.

First, set your permalink settings to 'Post name'. Read through Wordpress' template hierarchy to understand how things work: https://codex.wordpress.org/Template_Hierarchy
If you create a taxonomy-{taxonomy-slug}.php template, you can then navigate to myurl.com/paintings/{taxonomy}/{taxonomy-term} and use the following within your template
$taxonomy = get_query_var( 'taxonomy' );
$term = get_query_var( 'term' );
.. and use those variables in your query.
A single-{post-type-slug}.php would be used to render the post itself.
I would argue that it is not advisable to include the taxonomy in the URL of the post as these could change, or you could have multiple terms associated with a post. But, if it's necessary, check out this article: http://shibashake.com/wordpress-theme/add-custom-taxonomy-tags-to-your-wordpress-permalinks

Related

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

Archive-style page for a custom taxonomy

I've been trying with no luck to use built-in template hierarchy to get a simple page that would list all terms for a custom taxonomy.
I have a custom taxonomy "editions" (linked to a custom post type "courses").
I have my template that I named "taxonomy-editions.php" (also tried archive-editions.php) which is called when I try to access a given edition (/editions/2016 for example, and archive-editions.php does the same btw). But whenever I try to access /editions/, no template is called (apart from index.php).
Am I doing something wrong here, or is it simply not possible to do that without creating a custom page ? (most of the answers I've found are 2 years old or more).
Thank you in advance
If you are using the custom taxonomy , then please use the following templates for custom taxonomy and just copy the archive code over this template.
taxonomy-{taxonomy}-{term}.php
taxonomy-{taxonomy}.php
tag-{slug}.php
tag-{id}.php
category-{slug}.php
category-{ID}.php
Also don't forget to use this variables as true when you registering the taxonomy,
publicly_queryable=>true
hierarchical=>true
You can check the usage of register_taxonomy here.

WordPress custom post type archive with description

I have a common design pattern I'm not entirely sure how to best execute in WordPress. The layout is a listing of post teasers (title, trimmed body, image) on an overview page. Let's say example.com is a boating safety company, and at example.com/classes there's a listing of their posts of the class type using archive.php or archive-$posttype.php
So far it's dead simple and default WordPress behaviour. But, I want to have some intro information about this type of information in general on this overview page. Furthermore, let's say I have 10 custom post types hypothetically, and each one would follow this pattern with a listing and a general introductory paragraph on the archive page.
What I don't want to do is have a page for each of these types, and a custom query done for each of them in a page template. If there were a way to associate a description, and even better custom fields, with the post type itself (not on posts of that type but the type itself) that would be the ideal scenario. Ideally I'd like to have this all wrapped into my archive.php template.
Does anybody know of a good way to pull this off?
This may or may not be helpful, but I'll be creating post types in code but using Advanced Custom Fields for the custom fields themselves.
read up on creating post types there is a option for has archive, set it to no, it wont create the standard urls for list view etc. You can modify archive.php to include all post types as well.
I think you are confused about the way wordpress custom post types exist on your server. Basically they only exist in php code, so everytime the wp system loads, your custom code runs to create the custom post type...you are basically setting the rules of the post type at this stage -- so
Custom post type name
Arguments for post type (google create post type)
Custom taxonomies
Meta boxes for admin screen (recommended instead of using custom fields...)
Wordpress if it sees the posttype is public & has_archive will resolve any url requests for the post-type with the appropriate template...for example a post type of "mypost". In this case typing www.example.com/mypost will return back the archive view from your theme (archive.php or archive-mypost.php). This file is located in your theme and you can modify it to include a archive of all post types (replace get_posts with wp_query for total control over posts)
On these archive pages you will see a function called get_posts / wp_query and then standard loop structure to loop through each item. These functions query the wp_posts table in the database to return rows with the post_type you are querying (asking the function to find)(see the DB and the column post_type in wp_posts). There is also a secondary table to store unlimited extra fields (dont take me literally there, but in theory & memory constraints pushed aside, there is no limit set by WP on the extra fields) in a table called post_meta which uses the post id (unique identifer of the row in wp_posts). You can display this information by using get_post_meta() (google it)
So where does that leave you assuming there is a theme installed?
(prob best to create a child theme here)
create your custom post types in the functions file with a have_archive value of false in the arguments array
Add meta box function for the custom fields you want in your functions file (google this, very easy to do)
Modify your archive.php to run a new query for all post types (google wp_query, you can query a array of post types)
Any other info like descriptions, default save behaviour can be set using php in your functions file and hooked to the action you want to modify (eg save post, etc).
register_post_type() has a description arg which defaults to an empty string. You can use that and get the description like e.g.:
$obj = get_post_type_object( 'my_post_type' );
echo $obj->description;
If i understand correctly, you just need a different description loaded for each post type but maintaining a single archive.php, basically you just need to display the description like so:
<?php
if (get_the_post_type_description()) {
echo get_the_post_type_description();
}
?>

WordPress Custom Post Type Issue

my situation is I registered a custom post type named 'products' and I included 'has_archive' => true in the parameter to enable an archive template for this custom post type, I also created a archive-products.php as the template for displaying post per taxonomy of 'products', but what I noticed is when I enabled 'has_archive' => true what happens is archive-products.php acts as the index page template of the 'products' custom post type instead of the 'page-products.php' file that I created as the index page template for listing all the post of 'products' custom post type.
then when I click a link to the product-category this archive-products.php uses the default archive.php as it's archive page template. it really acts weird and now I don't know what to do next.
what I want to happen is prevent this from happening and let page-products.php act as the default index page template for listing the posts (as it should be) and for archive-products.php to be used by page-products.php as it should be doing.
thanks I hope someone can help me into this issue.
by the way I'm using WordPress 3.5.1
I faced the same problem in the last days, and take a couple of hours to search for a solution, in my case the solution was to add this following functions to you functions.php file: flush_rewrite_rules(false);
I hope it can help you :)
you can check this plugin for your custom post display
wordpress.org/plugins/wp-custom-post-field
on here create your custom post and use shortcode for display post.

WordPress custom post type category order

I'm looking for a way to manually reorder the category list for custom post types,
are there any plug-ins that already do this?
I can probably code my own, but I'm not sure where to start, can you add custom fields to the categories that can be used to order them?
Anything to point me in the right direction would be great!
EDIT [resolved]
After a bit more digging I uncovered this:
http://wordpress.org/support/topic/plugin-my-category-order-custom-taxonomy-order-and-code-improvements
Which linked to this:
http://snipplr.com/view/48599/mycategoryorder-custom-taxonomy-mod/
and once you change line 51 to you custom taxonomy type it works like a charm, eg:
$tax = ($_GET['mytax'])? $_GET['mytax'] : 'category';
becomes
$tax = ($_GET['mytax'])? $_GET['mytax'] : 'my_custom_taxonomy';
works perfectly with 'Types' plugin linked by #Ajay Patel, cheers.
Not able to get you question perfectly.
But use this plugin Types - Custom Fields and Custom Post Types Management
Types makes it easy to customize the WordPress admin. Define your own content using custom post types and custom taxonomy. Redesign editing screens using custom fields.

Resources