WordPress Custom Post Logic - wordpress

I'm a newbie here, but I've been trying to understand and research this for the past couple of days to no avail.
I created a custom post type (video) with a taxonomy associated with it (industries). The taxonomy "industries" has multiple categories (I'm not sure if in this case they are called terms rather than categories; correct me if I'm wrong!) such as IT, Construction, etc. For arguments sake, let's say under the category IT there is a single post named Web Developer.
First question: With the logic above, how would I manage to reach the single post (web developer) with the URL: .../video/IT/web developer?
Second question: If on the video page I would like to display all posts in all categories, what template page should I create? Is it archive-video.php? The same question goes for the category (IT in this case): Which template page should I create in order to display all posts under a specific category?

I'll answer your second question first:
Yes, the template you should use for displaying all the custom post types would be the CPT archive, so archive-video.php sounds right.
For the categories (the exact way to say it would be "taxonomy terms" indeed), you would use taxonomy-{taxonomy}.php or even taxonomy-{taxonomy}-{term}.php if you need to get more specific.
About your first question, there is currently no core functionality to use custom taxonomies in your permalinks, but this might help you.

Related

Connect one CPT to another CPT in a wp_query loop

I am looking for the most efficient way to create two separate custom post types called "venues" and "offers". The role of such would be to display on a website it in the following way:
VENUE_1
offer A
offer B
etc
VENUE_2
offer C
As you see, the venues will be quite static, once added photos and descriptions will remain the same. The most dynamic thing are offers. They will vary from each other. I know I can handle that through ACF repeater in a single CPT but I don't want to use this solution due to a few technical requirements.
Is there any way that Wordpress (or Wordpress +ACF) will allow to do that? From the flow pov it will look like that:
an editor adds venue, with descriptions, photos etc through venue CPT
along the time an editor adds specific offers through offers CPT, selecting via e.g. dropdown to which venue it is connected
I have never used relationship fields in ACF but afaik while selecting I need to do it fully manually and select very specific offer. And as said, I want to handle later on only offers, avoiding situation when constantly I need to add manually those via venue item.
You're probably over complicating things.
You should approach it from a taxonomy point of view, meaning,
venue as a taxonomy, offer as a custom post type.
You can use taxonomy-<my-taxonomy>.php to create a specific template for your custom taxonomy. eg: taxonomy-venue.php.
You will be able to access your venue through the following permalink example.com/venue/my-awsome-venue
On each venue taxonomy pages you will a custom query to loop through each offer which are listed under the currently queried venue.
You should read Template Hierarchy from the codex, to have a better understanding of templating.

Wordpress Add actions and filters only if certain condition met

I am customizing wordpress comments to add multiple custom fields. So i have added filters and actions to show fields, validate them, process them and finally show them in comments. I have written these and they are working fine.
However i only need them only for Post which belongs to specific category and comment is not a reply of any other comment.
I tried few things but nothing seems to work. Can somebody provide me a working solution.
Just to start, I think you could put conditions inside filters and not filters inside conditions. That said, for posts in category and category archives you can use the 'conditional tags' is category (for archive) and in_category (for posts):
https://codex.wordpress.org/Function_Reference/is_category
https://codex.wordpress.org/Function_Reference/in_category

Wordpress custom post type single as parent for archive

For a new project i like to have a single of my custom post type 'teams' as a parent of a custom post type archive and singles 'report' so i would like to have "Teams/{team-name}/reports/{report}".
I've tried to create a custom slug with the 'save_post' action/hook but it didn't work. On the editor page of a report i do have a custom field to select a team but ik look likes this is not usable on the save_post function yet. Does anyone have a suggestion?
Based on what you've indicated in the comments above, I'd be inclined to do away with the http://{website}/Teams/{team-name}/reports/{report} pretty URL and have a more simple http://{website}/Teams/{team-name} URL. It will be more intuitive to remember for visitors.
In the single for the Team CPT, you would include a loop for the archive type associated with the particular team. You COULD create a hierarchy of CPT where Reports are a child of Team but you will be heading down a slippery road that the parent/child relationship creates a lot of overhang when the types become populated.
There are a lot of threads about this, this is just one guys report on what happens when there are many hierarchical CPTs: https://wordpress.org/support/topic/hierarchical-post-type-w-heavy-data-set-fails-lots-of-custom-fields?replies=1
If you could create them as individual (non related) CPTs, and have a common category or taxonomy you could then in the single.php of your CPT include a loop for the archive, or alternatively in the archive for the reports, you could include a team header section. You could link the two on that taxonomy.
On a slightly different tact, if it is just some basic info you want to have about the team on the archive page, you could include a description in the reports taxonomy and depending on your theme (or custom coding) you could display that at the top of the reports archive.

Linking Custom Post Types in Wordpress?

I have three Custom Post Types in Wordpress: artists, writers, stories
Is it possible to "link" the posts? For example, if a story is written by a writer and illustrated by an artist, I would like to show in the story page a picture of the writer (linked to the writer's page) and other stories illustrated by the artist.
Use the Posts 2 Posts Plugin
It gives you the chance to make relationships between post types.
I used it to link Clients to Projects and it worked like a charm.
P.S.: The answer given earlier will be needed to, you will need to make templates to display this all.
You probably want a custom single page template.
Adding a new template for those post types is easy. You can add a new template for each post type, like "single-artist.php" in which you put together the page to display the artist info. On the "single-story.php" you can arrange it so that the appropriate links are added where necessary.

Wordpress: custom post types: using custom fields or taxonomies?

I'm thinking about using WP custom post types to create a basic real estate website.
The post type will be for property listings. I've decided to have one post type for For Sale and one for Rentals, simple because they have somewhat different property information.
A typical listing will need to specify some information, ie, is it a house, an apartment or maybe it's just a piece of land.
What are the pros and cons of specifying this info using custom fields (meta data) versus using taxonomy (categories and tags)?
I can see that it's easy to search based on taxonomy, but custom post types meta data can also be queried.
Also, it seems that this question applies to any post data where discrete choices are required: meta data checkbox, select or taxonomy.
Any thoughts?
Thanks.
My preference for what you're trying to do would be taxonomy for the following reasons:
SEO and User Friendly URLs
With categories and tags, WordPress permalinks are setup to put that information in the URL for you. This will go a long way towards the SEO and usability of your site because you'll be able to create URLs like:
http://yoursite.com/rentals
http://yoursite.com/for-sale/two-bedroom/123-fake-street
Hierarchy
I don't know if you have the need for it, but building a hierarchy with categories is easy. This will give you lots of flexibility when it comes to organizing your posts.
Theme Coding
As you said, it's possible to perform custom queries for meta data, but WordPress has many out-of-the-box functions to query and display based on tags and categories. This will mean that you'll have to write less code to get your theme to do what you want.
I've done exactly what you are talking about, both ways (using Custom Fields versus Categories). My view is you should use a mix - use Categories for the most important information (eg For Sale, Type of Property etc) and use Custom Fields for the actual data for the listing.
Wordpress then has many built in functions to organise that data in a really intuitive way, and allows you to easily group properties of the same type together, in exactly the way a user wants to browse the data.

Resources