In the Bricks Facebook group, a user asks:
Hey Everyone,
I am trying to create the following:
1- I have a Custom Post Type
2- I have a static page, and in the URL, I am displaying a URL parameter that contains the ID of the custom post type.
I want to display dynamic data (i.e. post title) on the static page, but based on the ID in the URL.
How can I achieve this result? I tried using the dynamic fields but not able to get the data based on the url parameter.
This tutorial shows how a single post (of any post type) can be output on a Page/template whose ID is taken from the URL parameter.
Consider this URL: https://example.com/sample-page/?page_id=24
We can set up a query loop on a Block element in Bricks, select the post type (post by default), set the number of posts to 1, enable no_found_rows, turn on PHP query and specify an array having the key of p and the value set to the value of the page_id URL parameter. This array will then be merged with the query loop’s array of arguments and any dynamic data like the post_title (in curly braces) inside the Block will show that specific post’s data.
Enable PHP query on the Block and paste:
replace post_id with the name of your URL parameter.
Add a Heading inside the Block and change its text to:
{post_title}
Additionally, you may want to add this dynamic data condition on the query loop-enabled Block to ensure that it gets output only if the URL parameter has a value.
