Using Dynamic Content in params for Looper Custom Hook doesn't work

Hi

I am trying to create a Custom Hook for my Looper which needs access to the current post id of the page

I have followed the instructions given in this post: Custom Looper params with dynamic content but it doesn’t seem to work as specified

Here is my hook

add_filter( 'cs_looper_custom_service_faq', function( $result, $params) {
		
$args = array(  
    'post_type' => 'faq',
    'post_status' => 'publish',
 );
	
$query = get_posts( $args );

return $query;
}, 10, 2);

And here is the JSON Supplied in the builder

{
    "postId":"{{dc:post:id}}"
}

If i try to var_dump the content of $params inside the code i get the following on page render

array(1) { ["postId"]=> string(14) "168" }

as seen it says that postId is a 14 char string, but the value is the post id. This seems to be that the postId inside the code actually holds the string value “{{dc:post:id}}” (as that is 14 chars) and not the post id.

So it seems like the value being sent to the hook isn’t evaluated before being executed or something similiar

I am running Pro Version: 5.1.5

Hi @Digixio,

Thanks for reaching out.
Instead of using the {{dc:post:id}} as a parameter, I would suggest you use the get_the_ID() method in the custom looper to get the current page/post ID. I would suggest you go through the following thread which helps you with this.

NOTE: Even if the var_dump shows the postID as a string it can be used in the Query String.

Thanks

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