9th Oct '24
/
2 comments

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 610 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Load more for Query loops in Bricks

Load more for Query loops in Bricks

Did you know that Bricks has AJAX loading for query loop posts on-click out of the box?
Categories:
Pro
Recently Viewed Posts Bricks Query Loop

Recently Viewed Posts Bricks Query Loop

How to output the most recent X number of posts (any post type) viewed by the current visitor.
Categories:
Pro
Current Single Post Reference From Inside a Bricks Query Loop

Current Single Post Reference From Inside a Bricks Query Loop

Use case: Get the single post’s custom field (like ACF Repeater or Meta Box Group) array row corresponding to the loop’s counter/index
Categories:
Using WP Grid Builder Facets with Bricks’ Query Loop

Using WP Grid Builder Facets with Bricks’ Query Loop

Update: This tutorial was written before WPGB had a Bricks add-on. Now, it is advisable to use that add-on instead. Get it from here. Updated…
Categories:
Pro
Parent post Bricks query loop

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…
Categories:
How to create filters with IsotopeJS in Bricks (Part 4): AJAX filter and infinite loops, Sorting, List view and Disable animations

How to create filters with IsotopeJS in Bricks (Part 4): AJAX filter and infinite loops, Sorting, List view and Disable animations

This tutorial will explain how to enable the AJAX filter with an infinite scroll query loop container, how to add a sorting function, how to…
Categories:
Random Posts in the Same Category as the Current Single CPT Post in Bricks

Random Posts in the Same Category as the Current Single CPT Post in Bricks

Here’s how query loop can be set in Bricks to show related posts by a taxonomy’s terms
Categories:
Bricks Query Loop – Posts Authored by Logged in User

Bricks Query Loop – Posts Authored by Logged in User

How to display only the posts authored by the currently logged-in user in a query loop.
Categories: