Parent post Bricks query loop

Updated on 5 Feb 2024

In the BricksLabs Facebook group a user asks:

Is there a way to output the data of a parent post in a child post?

Are there tutorials for this?

This Pro tutorial provides the steps to output the current single post’s parent post using a Bricks query loop for hierarchical post types.

When viewing the child post:

Step 1

Create and edit your single post type template with Bricks.

Add a Section for showing the parent post data (bottom Section in the screenshot).

Sample JSON provided near the end for copy-pasting.

Set up a query loop inside.

Click the query icon and enable PHP query editor.

Paste:

return [
  'post_type' => 'page',
  
  'posts_per_page' => 1,
  'post__in' => [wp_get_post_parent_id()],
  'no_found_rows' => true,
  'update_post_meta_cache' => false,
  'update_post_term_cache' => false,
];

Enter your post type on the right side in

'post_type' => 'page',

Sample JSON

Step 2

Add a condition on the Section to output it only if the current post has a parent.

{echo:wp_get_post_parent_id}

Reference

https://developer.wordpress.org/reference/functions/wp_get_post_parent_id/