We’re rewarding the question askers & reputations are being recalculated! Read more.

Questions tagged [relations]

Questions around Craft's relational field types.

Filter by
Sorted by
Tagged with
0
votes
0answers
18 views

Craft 3 match all categories using relatedTo in a module controller

I am trying to perform an entry query using relatedTo to get entries that match all categories. I know how to achieve this with 'and' in twig but I can't seem to find the correct syntax to use in a ...
0
votes
0answers
21 views

Plugin development | Update/push relation to existing one, not override

I am currently trying to update entries for a user. The problem is: If i am saving a new relation, it's overriding the one before. My .csv customUserId customEnryId 22 1000 22 ...
2
votes
2answers
94 views

Craft 3 version - How to get entries related to current category only (not children)

I need some help with syntax on this for Craft 3, please. I want to use this piece of code: {% set fruitEntries = craft.entries.relatedTo({ relatedTo: catP,id: 'and, not '~str }) %} from this ...
1
vote
1answer
31 views

Grabing data from another channel associated to an entry displayed using category

I have a page that shows a listing of entries (called products) by category. Those product entries have related content (reviews) stored in another channel that are tagged using a relations field. ...
0
votes
0answers
14 views

How to get category/entry url and a category url in entry breadcrumbs

I have entries for a channel called ‘resources’ that are related to multiple resource categories. When I call the category specific resource entries in a index, how can I get the url of website/...
1
vote
1answer
32 views

How do I flush the query cache?

How do I flush Craft's query cache so that I may query a relationship field again in the same web request with a new set of parameters? In this particular scenario, I need to handle it inside of a ...
1
vote
3answers
125 views

With a categories field, how do I query only the *selected* categories?

Suppose we have a category group that allows for any number of levels to its structure. We also have a category field that allows for choosing any number of categories from that group. In our example,...
1
vote
0answers
15 views

Adding Product Variant and Related Product to the cart together on Craft Commerce 2

I want to add a product variant as well as a related product (chosen from a select list) together when the user clicks the add to cart button. I can see you can add multiple products together with ...
1
vote
1answer
45 views

relatedTo - return only entries that have a related entry where a field in the related entry has a value

Trying to figure out if this is possible in 1 step. I want to return locations that have a related entry in the relatedMerchant field, but I'd also want to make sure that a field in the ...
1
vote
1answer
23 views

Getting entries from multiple categories

I have two categories, Annual Reviews and Publications. I want to get all entries from these and paginate them. The code I am using is fine for one category - both work individually, but as soon as ...
1
vote
2answers
55 views

Related To query

Struggling to get multiple relationship filtering working. So want to filter an entry (people) by one or more of the following: - location (entries) - specialism (categories) - team (categories) For ...
1
vote
1answer
33 views

How to include a lightswitch for each related entry in the source element of a relationship

I have a Services section in which I keep a related entry field for News. (News by Service) The News items to be displayed for each service are selected in a "News" entries field in the Service entry. ...
1
vote
0answers
79 views

Querying a supertable field

I have an entry type called people which has a superTable field called programmeAffiliations, with three fields, jobTitle, researchProgramme, primary where: researchProgramme is a category field (...
1
vote
0answers
47 views

What's the most performant way to get reverse related entries within an Element Query?

What's the most performant way to get reverse related entries within an Element Query? Here's a contrived example of this. I have thousands of "book" entries and thousands of "collection" entries. I ...
1
vote
1answer
34 views

Relations and Categories

What's given: Channel: Nutrition Entries Fieldtype: restaurant Category Fieldtype : menu Category: Menu Channel: Menus that also use relations using restaurant field. Each item in the nutrition ...
1
vote
1answer
48 views

Need help trying to pass a variable of a related entry

On my page, I have a form which is using Freeform (Solspace). I'm attempting to setup a custom redirect URL for the form. The form will apply to numerous entries in a channel and some will require ...
1
vote
0answers
58 views

How do I use a relation field in an element?

Currently I have a field that extends BaseRelationField, and 2 types of elements. I want the field on elements A to be able to select from elements B. So far the field itself works, which I tested by ...
1
vote
0answers
31 views

RelatedTo relation - checking matrix block status is enabled

I need to search for all commerce variants related to a custom element "Account". The account element is related to a variant through a matrix field with handle varientaccountmapping, block handle ...
1
vote
1answer
39 views

Relationship between channels/entries

I need some help. Really struggle understanding how to build relationships between channels/entries. Context/Want: I have two separate channels: 1. "Plant catalogue" 2. "Plant care" I want to re-use ...
1
vote
1answer
61 views

Get entries related to same category

I have a channel (handle: "infopages") with entries. I have a channel (handle: "products") with entries. I have a category (handle: "productTypes") Every entry from "infopages" has a category field, ...
1
vote
1answer
71 views

order by Table Number Field

% set entriesList = craft.entries.section('parks').relatedTo(entry.Line.one()).all %} {% if entriesList|length %} <div id="found-in" class="park"> <ul> {% for ...
0
votes
1answer
49 views

Displaying related image assets from another section with twig

I have a site that shows upcoming football matches in a table, and I would like to include the clubs' logos next to each club name. I have the following sections and entry types, both generated using ...
1
vote
1answer
39 views

Relation fallback if no category has been selected

I have a filter with a few different parameters that get pulled in and I was wondering if there was a relatedTo wildcard that I could use. Here's the relevant code: {% set function = craft.app....
0
votes
1answer
559 views

Craft 3 - Save new Entry with Relations (Categories/Assets)

i simply can not get my "job" done. I try to create a plugin for Craft, a simple one. It reads some date and should create new entries out of this data. First i stuck on a stupid save-mistake, someone ...
1
vote
1answer
35 views

Filter entries by other entry

There's a section called locations and another called vacancies. In vacancies the admin can assign a location entry to a vacancy. On the careers overview page we want to display selected vacancies ...
2
votes
0answers
293 views

Searching for Multiple Categories and Tags

I've been pulling my head for the past day on how to filter products with multiple categories. After a long search, I found and implemented on my project, Advanced Search with tags and categories It ...
1
vote
0answers
12 views

How can I use a double relation to include the currentUser as criteria?

I have a front-end form that allows registered users to edit content. In this case, it is a podcast. I have multiple podcasts that blog to different providers. Here is how I am selecting the provider ...
1
vote
1answer
33 views

How can I make related entries and globals part of the search considerations?

How can I make related entries and globals part of the search considerations? So I have a website search bar that searches the whole website. Within some jobs pages there are some global elements ...
0
votes
0answers
54 views

Indirect Relationship defined in Matrix Block

I have 3 channels: Reviews, Products and UseCases. In the section "Reviews" an entry has a list of "Products", based on a matrix field. Every block in this matrix field represents one listed "Product"...
1
vote
0answers
85 views

Sorting with reverse relationship

I have a overview page that combines with two sections (documentation and galleries). Those two sections are attached to a parent Event. So you can select in the event entry a gallery or a ...
1
vote
1answer
24 views

How to filter relational field types on their related content's status?

I have a Matrix field on Users. In that Matrix field is an Entries field. I need to pull all Entries from that field, regardless of the related Entries status. The following code returns Users but ...
1
vote
0answers
17 views

modifyEntrySources hook with reverse relations

Is it possible to do a reverse relation query in a custom entry source? https://docs.craftcms.com/v2/plugins/hooks-reference.html#modifyentrysources I have two entry sections, one called courses and ...
1
vote
1answer
74 views

Eagerload inverse relation

I would like to eagerload inverse relation. Business case: I have stories, stories are connected to books over relatedBooks field. Now I would like to query those books only which not have any story. ...
1
vote
1answer
61 views

SQL error when trying to use sortOrder on Matrix related block (Craft 2)

I'm getting the following SQL error when trying to simply order related entries in a Matrix block. Anyway around this? CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity ...
1
vote
1answer
25 views

CP: Title from relation?

I have the following 1:n relation between two sections: Source Element: Interview Target Element: Persons In the CP (only there) I need to be able to identify Interviews by the name of the ...
2
votes
1answer
63 views

How to exclude child elements when looping through categories?

I've got a few categories set up with a few child categories for each. Each one has assets (PDFs) assigned to them, by going into the assets, double clicking, and setting the category field there. So ...
3
votes
2answers
32 views

Display Stores by Region with relations

I need display Stores by Region, by example: Alabama Store X Store Y Idaho Store A Store B So: I create two channels Stores and Regions. In the channel Stores I create a entries field type ...
2
votes
1answer
288 views

Is there a way to check if entry is selected in relationship?

This project has a lot of user stuff. I need to display display different sections based on if the current user is in a field. Is there a better/faster way than looping through and checking if every ...
4
votes
1answer
382 views

Filtering multiple categories with URL queries

I am trying to filter using categories. I have to filters type and size, in the url. /products.html?size=medium,large&type=polo-shirt,jeans In my template, I am doing the following {% set sizes ...
1
vote
1answer
38 views

Many To Many Plugin Template Help

I am using the Many to Many plugin and wondering if the below is possible. I have a channel called Model ID. Model ID is then related to two other sections, Memory and SSD. I want to be able to link ...
1
vote
0answers
47 views

Check the field type of all the attributes of an entry

Here's the whole picture: I'm trying to make an API endpoint which should output everything from an entry: First I did this: public function transform(Entry $entry) { return $entry-...
1
vote
2answers
127 views

Relating to Solspace Calendar Events

I'm using Solspace Calendar for events, I also have a standard channel for reviews. What I need is the ability to connect the review with the event. Solspace offers "Calendar Events" custom type ...
3
votes
1answer
352 views

Craft 3 Element API: Query the “parent” entry of a “child” entry with Matrix blocks connected by an 'Entries' field

In a Matrix block field of a "page" entry, I'm using an Entries field to manually select a list of "article" entries to the "page" entry. When I query an "article" entry, is it possible to query its "...
1
vote
1answer
395 views

Combining Multiple Relation

I am trying to accomplish targeting but wondering if there is a way to combine these two? I took a look around and in the Craft 3 docs but I am a bit turned around on this, really would appreciate ...
1
vote
1answer
53 views

What is $source and $sources in BaseRelationField?

I see the following in BaseRelationField: public function settingsAttributes(): array { $attributes = parent::settingsAttributes(); $attributes[] = 'sources'; $attributes[] = 'source'; ...
1
vote
0answers
115 views

Order Entries by Category Fields (with fallback)

This is almost a duplicate of this question I have a section which I want to sort by category field. But the categories are not mandatory. When I apply |group('refSorter.first().title') it will ...
1
vote
1answer
1k views

Relational query get error “Getting unknown property”

I built up a plugin and inside the plugin I created the relation between Entry and Section using ActiveRecord, like below: In SectionRecord : class SectionRecord extends ActiveRecord { public ...
1
vote
1answer
18 views

List users connected to me

I have a relationship field within my member profile. It allows users to connect to each other, i can list those that currentUser is connected to, but i need to list all other members that are ...
3
votes
1answer
89 views

Find structure entries which parents relate to other entries

I want to select all children of all entries that fulfil specified relation parameter. I have tried this, but I think .isDescendantOf only supports single entry. Is this even possible? {% set ...
0
votes
0answers
57 views

Complex Relations

I've got a pretty complex relatedTo situation and I can't figure out if it's possible in Craft. Admin users have a field called "Admin Location" which is a Category field type, and may have more than ...