Using existing filters with loopers

Hello,

Using Pro’s layout builder (which I love!) I am building a custom layout for a client website of mine, to replace a template that exists for a custom post type. I have no problem using dynamic data to pull in things like Featured Images, text fields, etc. However I need to pull in a gallery of thumbnails into my layout.

The plugin that I am using already creates filters (these are used to populate the standard ‘out of the box’ custom post page), but i am having trouble using these filters to pull in the images I need into my layout.

I have followed your guide on how to create my own custom looper data - https://theme.co/docs/dynamic-content-and-loopers#custom - but this doesn’t explain the process of using an existing filter.

Could you let me know how to apply my filter to get the desired result?

Thanks in advance for your help.

Hi @littleshock,

Thanks for reaching out about this. The new Custom looper type does little more than give you a way on the PHP side to pass an array of items into the builder. This is very powerful, but does require you to code the integration yourself or work with a developer. Here are a couple of quick pointers:

  • The custom looper filter expects you to return an array
  • This array can contain a list of WP_Post, WP_Term, associative arrays, or scalar values (strings numbers) but every item should consistently be the same type.
  • If the items are WP_Post or WP_Term you can use the respective Dynamic Content fields to access them.
  • If the item is an associative array you can access the values inside each object with {{dc:looper:field key="some_key"}}
  • If the item is a scalar value you can use Looper > Current Item from Dynamic Content
  • Inside your custom looper you’ll want to fetch all the data out of the plugin you’re using via whatever public API they make available.
  • When you have that data available, you may need to process it somewhat to ensure what you are returning is an array of items.

Here’s a really simple code example. It expects the Custom Looper hook to be set to my_looper

add_filter( 'cs_looper_custom_my_looper', function( $result, $args ) {

  $items = []; // populate this from your plugin

  return $items;
}, 10, 2);

Hopefully this helps somewhat. We’re working on more videos about the subject - one of which will be a deep dive on coding custom PHP for loopers.

So while we can’t help you implement a 3rd party plugin integration, hopefully this advice gives you a starting point. You could also reach out to the developers of your plugin to see if they have any advice on retrieving the data you need.

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