Custom Looper having dynamic param

I am creating a layout for a CPT, of “courses”. Currently there are two courses added. I need to create a custom looper, to run a subloop on the course. This custom looper provider being placed on a div element within one of the courses. When try to use dynamic content {{dc:post:id}} in the param of the hook, it’s not being passed to the function.

When I do a var_dump() on the function output I see that the URL is rendering as a string with {{dc:post:id}} at the end just as it is the param. But I need it replaced with the actual current post ID.

Can we use DC in the params for a custom looper? Since its the archive layout the div should have access to the post:id so that the looper can be dynamic for each subsequent course id. What am I missing here?

My Hook:
sfwd_pricing

My param :

{
"url" : "https://myapp.cloudwaysapps.com/wp-json/ldlms/v1/sfwd-courses/{{dc:post:id}}"
}

My function:

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

$course_id = '101701'; // for testing
$api_url = isset( $args['url'] ) ? $args['url'] : null;
//$api_url = 'https://myapp.cloudwaysapps.com/wp-json/ldlms/v1/sfwd-courses/' .  $course_id;  //for testing

if ( $api_url ) {
  $request = wp_remote_get( $api_url );

  if ( ! is_wp_error( $request ) ) {
    $response = json_decode( wp_remote_retrieve_body( $request ), true );

    if ( is_array( $response ) ) {
      $result = $response;
    }

  }

}
return $result;
}, 10, 2);

Hey @designerken,

Please make sure to update to the Pro theme version 6.1.10 because our developers have made some updates to the Dynamic Contents. You can check out the changelog here:

Kindly let us know how it goes.

Hello @ruenel

I have already updated the Theme to the latest version.

The URL is still output literally as:
https://myapp.cloudwaysapps.com/wp-json/ldlms/v1/sfwd-courses/{{dc:post:id}}" when I do a var_dump for the string in the function.

I will set a request for running dynamic content on the custom looper content . I’m not 100% sure we can do that as some scripts might want to handle that differently, but see the below for now you’ll replace the URL line with something like this noting the function cs_dynamic_content

// cs_dynamic_content will expand any dynamic content string
// to it's current stack value
$api_url = isset( $args['url'] ) ? cs_dynamic_content($args['url']) : null;

@charlie

Thanks for chiming in here on the thread. That little snippet did the trick, I was able to run the secondary looper on the post type to grab the price. Thanks.

Is this a solution that would be ready for a production site or should I look for an alternative?

Hey @designerken,

Yes, you can use that in your production or live site.

Best Regards.

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