Custom Looper Random Post - Custom Example Not Working

I am trying to use the custom looper to randomly pull 1 post from a post list, or from JSON used within the looper. However, when trying to get the custom looper example to work, I am not seeing any result on the front end.

I have a Div set up as a looper provider set to custom looper with the hook set to my_data (as per the custom looper example)

I have a text element as a looper consumer and the content of the text element as {{dc:looper:field key=“text”}}

I then have the following code in the functions.php file of the theme:

add_filter( ‘cs_looper_custom_my_data’, function( $result ) {

return [
[ ‘text’ => ‘This is some text for the first item.’ ],
[ ‘text’ => ‘This is some text for the second item.’ ],
];
});

Nothing is showing up in the text element. I’m sure I’m missing something very simple, but I can’t seem to work it out.

Ideally I would be able to set up the custom looper, and then use a parameter from the filter to create a random number for the offset of a list of posts within the range of post IDs. But, until I can get the custom looper functional, I’m stuck.

Hey @edevita,

Thanks for reaching out!

It would be great if we could check and investigate your issue properly. To do that, please give us the following information in a Secure Note.

  • WordPress Login URL
  • Admin level username and password
  • Page URL or Layout Builder name

You can find the Secure Note button at the bottom of your posts.

Thank you.

see secure note

Hi @edevita,

I have checked and found that you didn’t mention the custom looper name in the Hook as shown in the given screenshot. I have added the name and the section start working.

image - 2023-07-26T155123.904

Thanks

I see, what happened was the default placeholder text for the Looper Provider Hook was already my_data, so I assumed that it was the default hook name and not simply placeholder text. That is somewhat confusing, and perhaps I would suggest that the placeholder text for the Custom Looper Hook be removed, so it is clear that the field is blank.

Hey @edevita,

We’re glad that my colleague was able to help you figure it out.

Thank you.

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