Connect one CPT to another CPT in a wp_query loop - wordpress

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.

Related

What is the best method for organizing geographical/city content in WordPress?

I want to create a news contributor network similar to that of yahoo.com. It will have categories such as events, sports, fashion, etc but I want the content organized into different cities. However, I would like some content to have the ability of being shared across all cities. What is the best way to structure this or set this up in wordpress?
Without knowing your complete situation, one solution may be to have categories used for topical reasons (as you already have) and have tags used for cities.
Adding this after your latest comment.
One solution would be to register a custom taxonomy for Cities.
You could assign this taxonomy to default and any custom post types you have. This would function the same as Wordpress categories do and you could assign a city yo any post.
The advantage of this users could then view all post from a selected city.
https://codex.wordpress.org/Taxonomies
The Wordpress codex should have everything you need to get this set up.

WordPress Custom Post Logic

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.

Wordpress: Using Custom Post Type for image list of Product

I have a Wordpress-blog with gift ideas where I write text based articles. I recently discovered Custom Post types which I believe is the solution to an feature I want to create.
What I want:
Be able to tag each custom post using the normal "Categories" and "Tags".
Create a 3x3 matrix with product images (custom posts) to be shown on top of each Category-view or Tag-view (followed by the typical article list in the category or tag).
Example:
Lets say I have a category "Gifts for mom" and tags "Pink", "Cheap"
In the category "Gifts for mom" I have 10 text articles (normal posts) discussing the difficulties of buying gifts for your mom
I create nine custom posts, each is a specific gift (e.g. A pink hairbrush). I want to place them in the Category "Gifts for mom" and tag them with "Pink".
When I view myrandomgiftblogname.com/category/gifts-for-mom I want to be able to get a view:
Gifts for mom
Product Product Product
Product Product Product
Product Product Product
Articles:
- This awesome article
- That awesome article
- Etc
I assume this is possible but don't really know where to begin. Could you point me in the right direction? Which Plugins do I need? Do I need to do any programming myself (or just plugin configuration)? Is this even possible?
The description is a bit broad, hence a bit broad answer.
Two things are needed:
1) A plugin to create the Custom Post Type.
It is considered best practice to let CPT's in Plugin territory. So you can swap designs and preserve your CPT functionality. In reality, you are asking for future problems letting this be handled by the theme.
Create your own plugin, which would contain a register_post_type and any extra configs.
Use an existent plugin, like Custom Content Type Manager.
Its Custom Fields features are quite handy as well.
Allows users to create custom content types (also known as post types) and standardized custom fields for each, including dropdowns, checkboxes, and images.
2) Learn how to use and customize WordPress Templates
http://codex.wordpress.org/Templates
Templates are the files which control how your WordPress site will be displayed on the Web. These files draw information from your WordPress MySQL database and generate the HTML code which is sent to the web browser. Through its powerful Theme system, WordPress allows you to define as few or as many Templates as you like all under one Theme. Each of these Template files can be configured for use under specific situations.
You can try the following:
Add a new Page for each category with the exact same name as the category.
In the Images menu attach to each of those pages the images you want.
In your script query for a page with a name identical to the current category, and pull all of its attachments

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.

wordpress select multiple results in plugin category post like style

I am looking at creating a selection pretty similar to the posts and categories in Wordpress admin page.
When you add a new post you can select multiple categories that it belongs too.
I have a video and playlist plugin that I need to associate with one another.
How would I go about achieving this?
Are you asking how to do this in the database, or in the UI?
In the database, you will need a many-to-many relation table (video_id, playlist_id).
In the UI, the easy way is to do it like the categories, and display a checkbox before each playlist. If you want it with autocompletion like the tags, you will need some AJAX tricks. You can get inspiration in wp-admin/includes/meta-boxes.php, in the functions post_tags_meta_box and post_categories_meta_box.
If you can adapt your code to use custom taxonomies, you will get all this for free.

Resources