Print

JCI and “Pods – Custom Content Types and Fields”

The Plugin “Pods – Custom Content Types” serves as a framework for creating, managing, and deploying customized content types and fields.

Create a CustomPostType with Pods and enhance it by adding some fields. Then, use the JCI PRO plugin to generate CustomPostPages from JSON, based on the blueprint created with Pods.

Furthermore, you can establish relationships between CustomPostPages using the JCI PRO plugin. For instance, if you have JSON data for venues, each with an ID, description, etc., you can generate a series of CustomPostPages for each venue. Similarly, if you have another JSON dataset for events, where the venue for each event is identified by a VenueID in the event JSON, you can also generate a series of CustomPostPages for these events.

The challenge lies in linking the venue pages with the event pages. This connection is achieved by defining a Pods relation in the settings for the venue and event Pods Custom Post Types (CPTs). However, to physically link the pages, you must use another script from twig-JCI PRO, which involves adding the venue ID to the event pages (and optionally, the event ID to the venue pages). To facilitate this, the JCI PRO plugin provides two functions:

wp_jci_pods_relation_add(pod_add_to_label, pod_add_to_id, relationship_field, pod_to_connect)

and

wp_jci_pods_relation_remove(relation_field, pod_label, pod_id)

Example of a full twig script adding and removing relations:

{# get pagesids of all venues #} 
{% set list_of_venues = {} %}
{% set cpt_slug_venues = 'pods-venues' %} 
{% set cpt_cpfkey_venues = "cptidentifier" %} 
{% set cpt_cpfval_venues = "pmd-uniqueidentifierforallpages" %}
{% set getallvenues = wp_get_cp_by_cpf_keyvalue(cpt_slug_venues, cpt_cpfkey_venues, cpt_cpfval_venues) %}
{% for crpg in getallvenues %}
        {% set pgid = wp_get_custom_field_value(crpg, "identifier") %}
        {% set list_of_venues = list_of_venues | merge({ ("pid"~pgid.0) : (crpg) }) %}
{% endfor %}

{# get pageids of events #}
{% set cpt_slug_events = 'pods-event' %} 
{% set cpt_cpfkey_events = "cptidentifier" %} 
{% set cpt_cpfval_events = "pmv-uniqueidentifierforallpages" %}
{% set getallevents = wp_get_cp_by_cpf_keyvalue(cpt_slug_events, cpt_cpfkey_events, cpt_cpfval_events) %}
{# loop through events #}
{% for crpg in getallevents %}
        {% set pageidevent = crpg %}
        {% set venueidarr = wp_get_custom_field_value(crpg, "venueofevent") %}
        {% set venueid = venueidarr.0 %}
{# get pageid of venue with data from event #}
        {% set pgidofvenue = attribute(list_of_venues, ("pid" ~venueidarr.0) ) %}
        pageid of event: {{pageidevent}}<br>
        pageid of venue: {{pgidofvenue}}<br>
        {% set createpodsrelation = wp_jci_pods_relation_add(cpt_slug_events, pageidevent, 'relation2venue', pgidofvenue) %}
      
        add to event: {{createpodsrelation}}<br>
        {% set createpodsrelation = wp_jci_pods_relation_add(cpt_slug_venues, pgidofvenue, 'relation2date', pageidevent) %}        <br>
        add to venue: {{createpodsrelation}}<br>
      
        {% set rem = wp_jci_pods_relation_remove("relation2venue", cpt_slug_events, pageidevent) %}
        remove relation2venue: {{rem}}<br>
        {% set rem = wp_jci_pods_relation_remove("relation2date", cpt_slug_venues, pgidofvenue ) %}
        remove relation2date: {{rem}}
         <hr>
{% endfor %}
Was this article helpful?
0 out Of 5 Stars
5 Stars 0%
4 Stars 0%
3 Stars 0%
2 Stars 0%
1 Stars 0%
5
How can we improve this article?
Please submit the reason for your vote so that we can improve the article.
On this page: