22nd Feb '26
/
0 comments

How to show data of a post whose ID is the value of a URL parameter in Bricks

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.

Get access to all 621 Bricks code tutorials with BricksLabs Pro

Leave the first comment

 

Related Tutorials..

Pro
Filtering posts by a group field’s subfield value with Meta Box when using a custom table in Bricks

Filtering posts by a group field’s subfield value with Meta Box when using a custom table in Bricks

Filtering a query loop to output only those posts with the value of a Select subfield of a Group field set to Yes when using…
Categories:
Tags:
Loop Item ID and Loop Item Object in Bricks

Loop Item ID and Loop Item Object in Bricks

If you are working on a Bricks site with specific requirements, chances are you need to grab the ID and/or object of the current item…
Categories:
Pro
Child Posts Section in Bricks

Child Posts Section in Bricks

This Pro tutorial provides the steps to limit the posts (can be of any post type) output by Bricks' query loop to children of the…
Categories:
How to populate a map with dynamic markers from a CPT using ACF in Bricks (PART 2)

How to populate a map with dynamic markers from a CPT using ACF in Bricks (PART 2)

This tutorial provides the PHP & JS codes that can be pasted in order to create a flying effect on map markers each time your…
How to Show Future Events in Bricks

How to Show Future Events in Bricks

One of the common requirements in WordPress is being able to filter the events (or could be posts of any post type) to only those…
Categories:
Pro
Bricks Query Loop – How to Insert Elements After Every Nth Post

Bricks Query Loop – How to Insert Elements After Every Nth Post

Update: Follow this tutorial instead. This Pro tutorial provides the steps to output element(s) in a Bricks' query loop after every nth post. Use case:…
Categories: