Post Data for the Current User in Bricks with Meta Box

Post Data for the Current User in Bricks with Meta Box

In the Bricks Facebook group a user asked:

I need help with Metabox and Bricks!

I have created a CPT "SalesRep" with multiple custom fields that has relationship with User.

In User Meta I have a Custom Field SalesRep, a dropdown that is being fed by "SalesRep" CPT Title (it’s a Post type Custom field)

In Bricks page I want to display Sales Rep that is assigned to the current logged in user along with their (SalesRep') contact details. I have no problem displaying the SalesRep name as it is anyway stored in the UserMeta but I have no idea how to pull in their phone number and email which are Custom field for SalesRep CPTs.

Any ideas?

Consider the following scenario.

  • CPT: SalesRep
    • Custom fields: Phone number and Email
  • User Meta: SalesRep (Type: Post)
  • Sarah Johnson (a post of the SalesRep CPT) has been set as the Sales Rep for User A
  • David Wilson has been set as the Sales Rep for User B

Requirement: When User A logs into the site and visits the Page (say, "Profile") he/she should see Sarah Johnson as their Sales Rep. When User B logs into the site and visits the Profile page, he/she should see David Wilson as their Sales Rep.

This Pro tutorial shows how we can configure a Bricks query loop to output the post data of the SalesRep CPT that is associated with the current logged-in user.

Setup

SalesRep CPT:

SalesRep CPT's custom fields:

'User Fields' field group:

When editing User A:

When editing User B:

After implementing the tutorial, Profile page on the front end:

When User A is logged in:

When User B is logged in:

Bricks editor

Add a Section and inside its Container, a h2 Heading that reads say, "Your Sales Rep".

Add a Block below it and enable query loop.

Click the loop icon. Enable PHP query editor and paste:

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Get access to all 558 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
Meta Box Checkbox List Query Type in Bricks

Meta Box Checkbox List Query Type in Bricks

This Pro tutorial provides the steps to add a new query type in Bricks builder for displaying the values of a Checkbox List type of…
Categories:
Pro
Excluding Duplicate Posts from Query Loops in Bricks

Excluding Duplicate Posts from Query Loops in Bricks

How to ensure that posts are not duplicated when two query loops are used on the same page.
Categories:
Pro
Filtering Cloneable Meta Box Group by Sub Field Value in Bricks

Filtering Cloneable Meta Box Group by Sub Field Value in Bricks

This Pro tutorial provides the steps to filter the rows of a Meta Box cloneable group to only those that have a date custom field…
Pro
Filtering Meta Box Cloneable Group by Select Subfield for Multiple Bricks Query Loops with Conditional Output

Filtering Meta Box Cloneable Group by Select Subfield for Multiple Bricks Query Loops with Conditional Output

In the Bricks Facebook group a user asks: Consider this cloneable Meta Box field group for a Custom Post Type called Tour: with the Tour…
Output HappyFiles Folders in Metabox Select-Field

Output HappyFiles Folders in Metabox Select-Field

This tutorial is part of a series where I'm gonna show you how to output custom HappyFiles Galleries and Sliders. Part one will cover a…
Categories:
Pro
Adding active class to the current term/post in a Bricks query loop on Term archives/single posts

Adding active class to the current term/post in a Bricks query loop on Term archives/single posts

Updated on 29 Feb 2024 In the Sibling Terms Bricks Query Loop tutorial, a member asked: How can I set the class "active" to the…
Categories:
Pro
Dynamic Source for Video Element in Bricks Using Meta Box Post Field

Dynamic Source for Video Element in Bricks Using Meta Box Post Field

This Pro tutorial provides the steps to set the source of a Bricks video element on single CPT pages to be the URL of a…
Categories: