therefinery/relatedentriesautomation

Provides a field specify selection criteria for providing related entries

0.3.10 2020-04-01 19:39 UTC

This package is auto-updated.

Last update: 2024-09-29 03:31:20 UTC


README

Provides a field specify selection criteria for providing related entries

Using with templates

Calling the field by itself will return an object that defines the query criteria for finding related entries. To turn this raw data into a set of useful entries you have to pass it into a filter service function that can build a real-time query and return a list of entity ids for related entries. The easyist way to do that is to use the craft.relatedentriesautomation.buildEnityQuery() function.

{% set entryIds = craft.relatedentriesautomation.buildEnityQuery(block.sourceCriteria) %}
{% set relatedEntries = craft.entries(entryIds).visibility('not  hidden') %}

relatedEntries contains a list of entries you can iterate over using {% for entry in relatedEntries %} or a similar twig function.

debuging output in templates

It's possible to outut the SQL that's used to fetch the result set to the page.

{% set queryinfo = craft.relatedentriesautomation.filterEntries(block.sourceCriteria) %}
{% set entryIds = craft.relatedentriesautomation.entityQueryWithIds(queryinfo.result) %}
<pre>{{ queryinfo | json_encode(constant('JSON_PRETTY_PRINT')) }}</pre>
{% set relatedEntries = craft.entries(entryIds).visibility('not  hidden') %}

Requirements

This plugin requires Craft CMS 3.0.0 or later.

Installation

To install the plugin, follow these instructions.

  1. Open your terminal and go to your Craft project:

     cd /path/to/project
    
  2. Then install the plugin:

     composer require the-refinery/relatedentriesautomation
    
  3. In the Control Panel, go to Settings → Plugins and click the “Install” button for RelatedEntriesAutomation.