Skip Navigation

[Resolved] Help with custom post types, custom fields and views setup

This support ticket is created 3 years, 9 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+00:00)

This topic contains 3 replies, has 2 voices.

Last updated by Jamal 3 years, 9 months ago.

Assisted by: Jamal.

Author
Posts
#1682449

I have another question. It might now fit in here but I write here because it's related to the search.
I have a public business list and a restricted business list. They are in relationships. Some of the search criteria is coming from custom fields on the public list, others are coming from ones on the restricted list(parent). Is there any way to pass a certain value from a restricted list to a public list and save?

The whole purpose of making 2 lists is hiding certain information from the general public. For example, now we have 2 prices (one on a restricted list and another one on a public list). I set this way because certain users want to keep their pricing different or unclear for the public. However for restricted list, they have to enter correct price to provide accurate information for certain viewers.

Ideally, If the author of a restricted list, saved a price, the price also applied to the public one, so he needs only enter once. If he wants to write his own price for public only, he can click a override box and set a new price for public list independently. ( I would like to apply the same setting to other fields as well such as rent and etc.)

As of now the list result shows two prices $0 and other price. I was testing this logic but I was't sure if Types plug in can do this or not.

If there is a mean to do this, could you please provide how to.

Thank you.

#1683709

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

Hello and my apologies for the late reply.

I am not really sure to understand what you want to achieve, but I'll give it a try:
Is there any way to pass a certain value from a restricted list to a public list and save?
This will need custom code hooked to the action of saving one post, the code will then save the values to the other posts.

Do you want to display both restricted an public lists on the same view?
Do you want to display information from a restricted list on a public list based on a relationship between the two posts?

Can you provide more details?

#1684515

I am sorry that I didn't explain clearly.

my site has 2 custom post types
1) public business listing
2) restricted business listing.

The reason I set up this is to set certain information private.
If a user comes to want to see about information in a list. They can only see the public business list. If they want to see more information. They need to request information and get access to a restricted business listing of the public business listing.

one public business list and one restricted business list is related by one to one relationship.

When a paid user want to create a list, they submit a post form for restricted business list form, pay, and enter all information(e.g. address) which he wants to keep private that only requested user can access. Then he creates a public business list and enter some information he doesn't mind to reveal to the general public and save.
At this point. this user has one restricted business list and one public business list. They are parent and child relationships. But, their information is independent of each other. e.g. he can enter exact address on restriected business list, but he enter only zip code on the public business list.

My 1st question is.
When he create/edit or save the public business list(child), can toolset automatically pass parent's address into child's address field and save it somehow? So if he doesn't mind expose the exact address, he doesn't have to do anything. And the address field of the child post contains the same address from its parent list.
But if he wants to enter only zip code, he can click a checkbox to override, so he can actually fill in the address field his zipcode only.
So, the child post's address field only contains Zipcode.

If this is doable, that's great!

If not,
My 2nd question is: can my top page search filters from its parent's value? Right now, my search view queries the "public business list" Thanks to your help, I was able to make it work. Thank you.
But can add any filters from its parent value? for example, It's parent's restricted business list has an alcohol license Yes or no field. But I cannot use this custom field to filter the search result.
So I had to create the same alcohol license field on its child post so the users can search. But it is really redundant and it's confusing.
I would like to eliminate this repeat value. the post author has to enter the same information twice and it might cause a problem.

If my question No.1 can be doable, I don't have to worry about 2nd question because I can use child's post custom field to filter right?

Do you have a better picture of what I want to do? Please let me know if you are not sure some.

#1685203

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

Thank you for these details, I think I have a better understanding.

To answer your first question When he create/edit or save the public business list(child), can toolset automatically pass parent's address into child's address field and save it somehow?
This is not supported out of the box by Toolset. But it can be done with custom code.
Toolset forms always act on one single post. They can't update two posts unless we use custom code.
The custom code solution can be simple. You will need to hook into the save process(either from a form, or from the WordPress backend). Using Toolset relationship API, you can get the related post(public listing), then you can copy values from the private post to the public post or vice-versa.
- Hook for Toolset Forms: cred_save_data https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
- Hook for backend: save_post https://developer.wordpress.org/reference/hooks/save_post/
- Related post API: toolset_get_related_post https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post

Regarding your second question can my top page search filters from its parent's value?
This is also not supported out of the box by Toolset. You can't filter a query for a custom post type(Public lists) by the custom fields of another custom post type(Restricted lists). You can filter by the relationship, I mean the related post, but it can't go further and filter with the custom fields of that related filter.
Toolset is very powerful, you can archive this with custom code, by hooking into the view query process and adapt it to include the logic of filtering with the related posts custom fields, but it could be more complex or it could have a performance hit depending on how the post types, relationships, and the custom fields are configured.
- Hook for the view query: wpv_filter_query https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

On the other hand, you can pull the data from the related post directly with Toolset. For example, when listing public lists, you can check for a custom field on the public list('override info') and conditionally display the value of another custom field('address'), or display the custom field('address') from the related post.
Depending on whether you are building your views with legacy editor or with the block editor, the way to display the custom field from the related post can be different.

I hope this answers your questions. I remain at your disposal if you have any doubts or other questions.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.