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);