Looper/Consumer on a Single Layout post meta and query strings

I have a Single Layout I created for a CPT called events (using a plugin called TheEventsCalendar). This plug-in also created another CPT called Organizer and can assign multiple organizers to an event. I have an event with 2 organizers.

When I am adding the post meta I can see that the post is referencing the IDs of the organizers that are created and assigned to the post:

_EventOrganizerID = 2989
_EventOrganizerID = 1900

So I created a div and added a looper with a query string as follows:
post_type=tribe_organizer&posts_per_page=0&post_status=publish&orderby=title&order=ASC&offset=0

This returns all the organizers that have been created.

How do I filter out the two IDs that are part of the post meta?

If I alter the string to:
post_type=tribe_organizer&posts_per_page=0&post_status=publish&orderby=title&order=ASC&offset=0&p={{dc:post:meta key="_EventOrganizerID"}}

This query will pull in the data for the organizers but only the first one (ID = 2989)

How do I then loop through the post meta IDs? I assume that I need to make an array for the p key in the string but I am unclear on how to do this.

1 Like

Hello @designerken,

Thanks for writing to us,

Yes, you need an array for it, In case if you are not sure about how to add an array in the query string please have a look at this thread to learn more about how to write a custom query string with the array.

Hope it helps
Thanks

YEs I know how to add the array, but how do I add that array in with dynamic content is where I struggle.

This works manually.
post_type=tribe_organizer&post_status=publish&order=ASC&orderby=title&offset=0&post__in%5B0%5D=2989&post__in%5B1%5D=1900

How do I loop though each instance of _EventOrganizerID to populate the array so that I can add them to the query string?

Hello @designerken,

You need to run a new loop using the Looper Provider Query String where you can use that query. You can then have a Looper Consumer to display the _EventOrganizerID ID.

Alternatively, you can use the Terms (Minimal) dynamic element and modify it where you insert the query string and your Event Organizer ID instead of the terms.

Hope this makes sense.

@ruenel

It makes a little sense but I cannot seem to get this to work as you stated. I have tried both with the Query string and the terms element, I can get the first organizer but not the second. Or I can get it to list all the organizers that have been created (but not specifically assigned to the post).

SOLVED

I created a custom looper provider based off this function tribe_get_organizer_ids(); this helper function for the calendar returns ALL the IDs for an event.

Here is that function:

function dk_get_all_organizers_for_event() {
  $eventorganizerids = tribe_get_organizer_ids();
  return $eventorganizerids;
}
add_filter( 'cs_looper_custom_event_organizer', 'dk_get_all_organizers_for_event', 10, 2);

Then on my column I added that provider and it gave me this gave me the IDs and the count, I added a row element and set as the consumer to use that data (this generates 1 row for every ID).

Then in the column for that row I set a query string provider that would use that custom looper:
post_type=tribe_organizer&post_status=publish&order=ASC&orderby=title&offset=0&p={{dc:looper:item}}

In this string {{dc:looper:item}} is the ID for the organizer generated by the custom looper.

This part was the struggle: I had set the same column to be the consumer (as well as the provider) I kept trying to go the the next level down to consume the data but it would not work. I had to be the same element.

After that it was just adding in the {{dc:post:title}}, {{dc:post:meta key="_OrganizerPhone"}}, etc.

I would most likely need to do this a different way if there were 100s of organizers for these events (mostly there are 1 or 2), since the query string is being looped. If you have a suggestion on how to remedy that I would be all ears.

Hi @designerken,

Glad to know you are able to find the solution. Please let us know if anything further is needed.

Thanks

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.