Linking tables in Drupal 7 - drupal

I cant figure out how to link fields between 2 content-types in Drupal 7. For example...
I'm building an online shop using Drupal 7. There are several product categories and each category has its own page that displays all the products in that category plus a category description.
I store this data in two tables (content types). See below.
categories content-type:
category_name, description
----------------------------------------------
paintings, "A selection of paintings that we supply. Prices include ...."
ceramics, ....
jewellery, ....
.
products content-type:
name, category_name, price, ...
---------------------------------------------------
mona-lisa, paintings, £10,
necklace1, jewellery, £20,
necklace2, jewellery, £30,
.
The common field is 'category_name'. In the first table I define all the values for category_name and in the second table, each time I add a new product, I want to be able to pick one category to assign to the product. Does anyone know how to do this?
You can reuse fields between content types but you cant change the widget type (the 'categories' content-type needs free-text entry and the 'products' content-type needs a selector.
In Drupal 6 there seemed to be a 'node reference' field type which might be what I'm looking for but I cant figure out how to get this in Drupal7.

This module is still in progress but you can use references for that.

Related

ACF meta key field displays Array when field is of "relationship" type in post grid plugin wordpress

In wordpress I have a custom post type (generated through the ACF plugin) of job offers which include several text fields (meta_key values) which the plugin "post grid pro" will display no problem. However, I have one field which is the agency that posted the job offer.
This is a relationship field and whenever I add this meta_key to the list of fields to display within each block of my grid it displays simply "Array".
I have tried creating my own shortcode to display this field but alas, this does not work.
There is a page in the site, written by one of the original developers, which lists the job offers. They have managed to display the title of the job agency in php with:
<?= get_field("agence")[0]->post_title ?>
I would like to be able to either write my own shortcode to display the agency title or somehow dynamically create a new meta_key for each job offer which contains automatically the name of the agency derived from the relationship field "agence".
Any help would be vastly appreciated.
Instead of using the relationalship ACF field type, use the one called "Post Object". As long as you don't enable "Select multiple values?" option this will only return a single post object.
This post lists the difference between the two field types. Basically, they both return post objects, but they have slightly different options, and relationship fields always returns the result in an array. You could technically use the relationship field and set the minimum and maximum number of posts to 1, but the post object field is the most appropriate one to use when you only want a single post.

calling of one taxonomy from another taxonomy, so both of them have used in the same content type

Can we call one taxonomy term from another as a parent and child relation for example I need to click on product category and that show me product series page and when I click on product each series that will lead me to actual product detail means node, so I have two taxonomies category and series I am about to click on category to carry me to series page and then to click on series page to carry me to product detail page on the concern series”
no codebase problem
i am expecting that these two taxonomies may be used as i have mentioned in the question summary but, i can't do it so i hope some help in resolving this issue
Let's look at this answer, I hope it will help you.
Taxonomy terms from the same vocabulary filtered and referenced on multiple content types
To do this you’ll need to have the Entity Reference module installed. So get that out of the way quickly with drush dl entity reference -y and drush en entityreference -y if you haven't already.
First up, we need the taxonomy set up.
Let's demonstrate with the help of an image.
You’ll notice that these terms could be more or less grouped into two categories: Transport and Sleeping. One term (couchette) kinda fits both criteria and is there to exemplify the reason for not using 2 different vocabularies to handle the issue. Now we need to technically make the distinction between these terms as well and since they are entities, we can use a field for that.
So we can now go ahead and add a new field to this vocabulary of the type List (text) with whatever widget you’d like (and let’s call the field Type). You should make the allowed number of values unlimited and put the following in the allowed values list:
Edit each term and select the appropriate type. As expected, for the term couchette, you should select both options.
Now that we have our taxonomy squared away, it’s time to create a View that will handle the filtering of these terms. Because if we now add the Tags taxonomy term reference field to our content types in the normal fashion (as it is already present in the Article content type) we’ll be able to select all the terms in the vocabulary for all the content types. And that's not what we want now.
So create a drupal 7/8 View that shows taxonomy terms of the Tags vocabulary - let’s call it Tags Filter. Add 2 displays of the type Entity Reference and a filter of the field we added to our terms earlier. So for instance the first display can show the terms which have Sleeping selected and the other one can show terms which have Transport. Save the View and you can close it.
Now finally we can edit our content types and add to each a new field of the type Entity Reference with a select list widget. For the target type select Taxonomy term and under Entity Selection choose the following: for Mode, go with Views: filter by entity reference view and then select the View in question - one of the two displays which we created earlier. In the picture below, I named one of the displays

Make Drupal 7 Group by always show grouping field

I have a Drupal 7 view similar to the one described here: Drupal 7 Views - list group by field
I wish to have all the groupby fields always appear even if there are not members of them and ideally I wish to put a default value in such a list.
eg:
Foo:
-Jay
-George
Bar:
-Barry
Boo:
Sorry no entries at this time!
Suggestions?
If none of what you are fetching with the view is associated with the group 'Boo' then the view doesnt know it exists, so would never be able to show it but say there is no results for it.
What i would recommend is creating a taxonomy vocabulary with the terms: Foo, Bar, Boo.
In whatever content type your names belong to, create a term reference field, and link them to the terms.
In the view, fetch the taxonomy terms, create a relationship to the content type that references the taxonomy, and pull those through based on that. There is a setting in views for multiple results to combine into one field (so you would want to do that). Then you could add the 'Sorry no entries at this time!' as a field's no results text.
So to recap: VIEW => TAXONOMY TERMS => NAME CONTENT

Filter by custom field in WordPress admin list

Hoping that someone can help me with this rather frustrating issue:
I'm using Advanced Custom Fields for a custom post type called "customer_reviews" that has 2 custom fields: "cust_rating" (1-5) and "customer_tech" (ACF relationship field that returns 1 ID from another custom post type called "staff_members").
What i want to do is show 2 filter dropdowns in the admin list for "customer_reviews". One should say "Rating" and the other "Technician". The idea is to filter reviews by either x-star rating or technician, or both, meaning that for example, i'd like to show all 4 star reviews that are related to the technician "John Doe" and vice versa. I've researched how to add custom field filters to the admin list and here is my code so far: http://pastebin.com/5reZrEMk
The problem i keep running into is that when i filter by "Rating", i get the correct number of posts with that rating, but if i filter by "Technician" i get an empty list.

Extra options for Custom taxonomies Wordpress

I have to add simple options to my custom taxonomy (genre) for each custom post included in that specific taxonomy.
Taxonomy name: Genre
Taxonomies: Blues, Jazz, Rock
Custom post name: Bands
Bands: Band One, Band Two Band Three, Band Four
So basically going to the Jazz taxonomy options, should give me options for the Jazz bands:
Band Two {text_field}
Band Four {text_field}
I'm not achieving this with Advanced Custom Fields so I guess I need to write it? Or is there a plugin to save my life? If not where should I start looking?
If what you mean is that you want to extend your custom taxonomy to have more fields that the default: Name, Slug and Description, you can:
Use a massive plugin like Pods, which allows you to do what you want to do and much more stuff. See their docs.
Use a simple plugin like Tax-Meta-class, intended just for that purpose, which does not add many (probably unnecesary) code.
Try to do it manually, like in this example.
Note that I have not used any of these, but I'd strongly suggest you to try the option 2.
EDIT
Actually, if you're already using Advanced Custom Fields plugin, it allows you to do what you're looking for!
You just need to create a new Field Group and set up the custom fields you want as usual. Then, in the box Location, you need to set a Rule like this:
Show this field group if Taxonomy Term ----- equals to -----
Genre
This way you have all the power of ACF to create select-boxes or whatever you need...
EDIT 2
If what you want is to have different custom fields in a Post, depending on the Terms that this post has for a given taxonomy, you have to set up a Rule for your Field Group like this:
Show this field group if Post Taxonomy ----- equals to -----
Jazz
This will display this Field Group in all the Bands with a value of Jazz in the Genre taxonomy...

Resources