Skip Navigation

[Resolved] Filter custom field in Repeatable Group by current user id in view query

This support ticket is created 3 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

This topic contains 8 replies, has 2 voices.

Last updated by Jamal 3 years, 11 months ago.

Assisted by: Jamal.

Author
Posts
#2241459
View custom field filter.png
Kind custom fields.png

Custom post type Kind (child) contains a Repeatable Group with a Select field named Sponsor.
The custom field content of the Sponsor field contains the WP User ID.
A repeatable group is necessary, because a Kind can have multiple sponsors.

Now I would like to create a view where all Kind records are displayed where Sponsor has the current user ID.

I found this post:
https://toolset.com/forums/topic/how-to-filter-by-current-user-id-in-view-query-filter/

I tried to use this shortcode in the shortcode attribute: [wpv-view name="mijn-sponsorkinderen-view" sponsor="[wpv-user field='ID']"]
But when saving, this message is shown:
Only lowercase letters and numbers allowed as shortcode attributes.

How to define the query filter properly?

The functionality is under construction on development enviroment hidden link.

#2241527

Hello and thank you for contacting the Toolset support.

In the query filter, when you choose a shortcode attribute, you must enter the name or label that will be used as the shortcode argument when calling the view. In your case you should enter "sponsor", so you can use it in the view's shortcode:

[wpv-view name="mijn-sponsorkinderen-view" sponsor="[wpv-user field='ID']"]

This will let you save the shortcode attribute. But, it will not help you achieve what you want. Because the Repeatable Field Group is actually a post type related to Kind using a hidden One-to-Many relationship, and you cannot query the parent post(Kind) by custom field of the child post(Repeatable Field Group).

IMHO, because you are saving only one field in the Repeatable Field Group(RFG), why not dropping the RFG, and use a simple field that can accept multiple values. This way, your view will work, because it will query posts(Kind) through their own fields(Sponsor), rather than the field of a related post(RFG). Does it make sense?

#2241587
Select field.png
Lowercase letter message.png

Thanks for your reply Jamal!

I've followed your advice and ditched the Repeatable Group, but I don't see the multiple values option in a Select field. It needs to be a select field (see attached screenshot), because the author needs to be able to select the sponsor. (The Sponsor field values are set by a custom query on the user table).
Or do you have another way of using selects?

I also still get the 'Only lowercase letters and numbers allowed as shortcode attributes' warning when entering the shortcode in the shortcode attribute. Any idea how to solve this?

#2241671

For the shortcode attribute issue, you just need to enter the shortcode argument name: sponsor. Check this screenshot hidden link

Regarding the first question, would you allow me temporary access to your website to check this further? Your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **

Please let me know where the view is used on the frontend.

#2241743

Unfortunately, I can't reach the login page at /wp-login.php or /wp-admin/ Can you provide the login page URL?

I am sure you will understand that, as a supporter, I work on different wordpress installations per day, can you please share direct URLs to all that is involved:
- The URL of the view.
- The URL where the view is used.
- And example of expected outcome based on the provided user.

#2241755

Apologies, the URL = hidden link.

The view is used at:
hidden link

The view is inserted using this script:
hidden link

PS. I'm still working on the styling of the mijn-sponsorkinderen-view , so don't mind the layout 🙂

#2241777

My apologies, I mistakenly though that Select fields could be repeatable. It does not seem to be the case.

I am afraid, you will need to create a new custom post type(Sponsors) to present the website users. Then create a relationship to the Kind post type. Then you can include a relationship filter to filter the view based on the sponsor. Check this article, it could explain the idea better https://toolset.com/course-lesson/how-to-create-custom-searches-and-relationships-for-users/

I'll remain at your disposal.

#2241803

No problem, we decided to have only have 1 sponsor per child. So we're good with the single select field.
Can you help me out getting the view filter working, please?

#2242031

Sure. If there will be only one sponsor per Kind post, then we could save its ID on the sponsor custom field. In Then, you could have a custom field fitler on the sponsor field. And tada!!!
It should work as expected. If it does not, let me know where you get stuck, and I'll do my best to help.