Skip Navigation

[Resolved] Displaying CPT based on a search with categories / subcategories

This support ticket is created 4 years, 2 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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: Asia/Kolkata (GMT+05:30)

This topic contains 17 replies, has 2 voices.

Last updated by Jaime 4 years, 2 months ago.

Assisted by: Minesh.

Author
Posts
#1484437

Tell us what you are trying to do?
I have a CPT with custom taxonomies which involves hierarchical structure like "grandfather taxonomie" / "father taxonomie" / "grandchild taxonomie".

Let's say I have "Country 1" / "State 1" / "City 1" and "Country 2" / "State 2" / "City 2"

I would like to have :
1) User can create a CPT selecting "Country 1 /taxonomie" and then only "State 1 /taxonomie" and "City 1 /taxonomie" will be selectable. If user choose "Country 2 /taxonomie" then "State 2 /taxonomie" and "City 2 /taxonomie" will be selectable.

2) In search it should works the same. User searching for CPT should select first between "Country 1" or "Country 2". Then depending on the selection the options will be "State 1 / City 1" or "State 2 / City 2" options.

Other way to solve my problem would be:
I have a Field inside my CPT called "Country". Then, depending on the selection of this Field different taxonomies will be displayed.
(for example: If user select in the field 'Country' the 'Country 1' option, taxonomies for 'Country 1' will be displayed. And if 'Country 2' option is selected taxonomies for 'Country 2' will be displayed.
The same functionality for the search.

* I'm not sure which option is better and more logic. I'm a little bit confused with this... Sorry.
:/

Is there a similar example that we can see?
Yes, I think it's a pretty basic functionality like real state demos, isn't it?
The thing is users can select "child" taxonomies depending on their "parents" selections.

What is the link to your site?
hidden link

#1484521

Hi Minesh.
Just want you to know I'm using this example:
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/how-to-filter-posts-by-their-ancestors/

but I think I'm not able to reach a solution because I don't have this "Parent" / "Child" structure created.
🙁

Thanks in advance!
(I know you're great supporter!)

#1484541

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

The only way to search the posts with a dependent dropdown is to create a post type for every entity.

Having said that, The Country, States and Cities should be setup as post types and you can relate them with each other by creating the post-relationship.
- One County Have Many States
- Once State Have Many Cities.
=> https://toolset.com/documentation/post-relationships/how-to-set-up-post-relationships-using-toolset/

And then, you need to follow the Doc you shared:
=> https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/how-to-filter-posts-by-their-ancestors/

You can see it live in action with the real estate reference site:
=> hidden link

You may try to create a test site on our free test platform discover-wp.com and try to install the real estate reference site and play with it to learn how those dependent dropdowns for state and city is configured and latest you should configure it on your site accordingly.

#1484629

Hi again Minesh.
Thanks for your answer.

I'm not sure if I understood correctly.

Now, I have a CPT called "Companies" with
- a 'Select field' with two options ('Type company')
- a hierarchical list of over 100 taxonomies ('General activity' > 'Specific activity')

What you are suggesting is to create new CPTs for all this?
- Type Company (2 types of options) [Select field]
- General Activity (20 types of options) [Taxonomy parent]
- Specific Activity (60 types of options). [Taxonomy child]

So, if I do what you are suggesting, what should I do?

1) Create one CPT for "Type company" with a 'Select field' with 2 options
2) Create one CPT for "General activity" with a 'Select field' with 20 options.
3) Then, create a One to Many relationship (Type company -> General activity)
4) Then, create a CPT for "Specific Activity" with a 'Select field' with 60 options.
5) Then, create a One to Many relationship (General activity -> Specific activity)
6) Finally, I should insert all those CPT as fields inside my CPT called "Companies".

Is that what you are suggesting?

There is no other option like show in the search specific taxonomies depending on the selection of the field "Type company"?
I mean, If I have in my search a 'Select field' with two options, option 1 will display another 'Select field' with taxonomies called 1 and option 2 will display another 'Select field' with taxonomies called 2

Please let me know, because if the first option is the only way to do that I have to change all my we structure and I have lots of users registered now...

Thanks a lot Minesh.

#1484787

Hi Minesh.
I found this topic.
I think it shows a way to make an easier approach to my problem right?
https://toolset.com/forums/topic/search-filter-taxonomies-approach/

Here I can hide/show different taxonomies depending on the search, right?
Please tell me if this could be a workaround.

Thanks a lot Minesh for your help.
🙂

#1484817

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Yes - the thing is that you can setup the dependent filters using the first choice only, by setting up post types, there is no other option.

1) Create one CPT for "Type company" and add those 2 posts to it
2) Create one CPT for "General activity" and add those 20 options as post to it
3) Then, create a CPT for "Specific Activity" and add those 60 options as post toti
4) Then, create a One to Many relationships (Type company -> General activity)
5) Then, create a One to Many relationships (General activity -> Specific activity)
6) Make sure to connect the posts in relationship like connect Type company post to General activity and so on for your other relationship.

And then try to follow the following doc to add those fields a select field on your view as filter and that will allow you to update the related posts.
=> https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/how-to-filter-posts-by-their-ancestors/

#1485063

Thank you again Minesh.
But why this solution is not a good solution?
https://toolset.com/forums/topic/search-filter-taxonomies-approach/
Filters can be hide/shown depending on the first URL parameter of the filter, didn't they?

I mean, I have it working now like this

[wpv-filter-start hide="false"]
[wpv-filter-controls]

<div class="row">
  <div class="col-sm-12">
  <label>[wpml-string context="wpv-views"]<h6><span style="color: #ffffff;">Búsqueda por texto</span></h6>[/wpml-string]</label> 
		[wpv-filter-search-box output="bootstrap"]
  </div>
  <br>
	<div class="col-sm-3">
      	<div class="form-group">
<div class="form-group">
	<label><h6><span style="color: #ffffff;">[wpml-string context="wpv-views"]Tipo de empresa[/wpml-string]</span></h6>
  </label> 
<div class="form-group">
	[wpv-control-postmeta field="wpcf-tipo-de-empresa" url_param="wpv-wpcf-tipo-de-empresa" default_label="Todas"]
  
  
</div>
          </div>
      </div>
 	 </div> 
  	<div class="col-sm-3">
      <div class="form-group">
	
        <label><h6><span style="color: #ffffff;">[wpml-string context="wpv-views"]Categoría profesional[/wpml-string]</span></h6></label>
	<div class="form-group">
        
		[wpv-conditional if="( '[wpv-search-term param='wpv-wpcf-tipo-de-empresa']' eq 'Profesional' )"]

[wpv-control-post-taxonomy taxonomy="categoria-guia-produccion" type="select" default_label="Todas las categorías" url_param="wpv-categoria-guia-produccion"]
      
[/wpv-conditional]
      		[wpv-conditional if="( '[wpv-search-term param='wpv-wpcf-tipo-de-empresa']' eq 'Empresa' )"]

Empresa
      
[/wpv-conditional]
      [wpv-conditional if="( '[wpv-search-term param='wpv-wpcf-tipo-de-empresa']' eq '' )"]
<label for="basic-url">      <font color="white">Seleccione categoría</font></label>
<div class="input-group mb-3">
  <div class="input-group-prepend">
    <span class="input-group-text" id="basic-addon3"><em><u>hidden link</u></em>;
  </div>
  <input type="text" class="form-control" id="basic-url" aria-describedby="basic-addon3">
</div>
      
[/wpv-conditional]
        </div>
</div>
  </div>
#1486715

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

What you need is a dependent dropdown, so when I select option from dropdown select 1, it should update the options on dropdown select 2.

Using [wpv-conditional] statement, you can display the content, filters conditionally but it will not update the dropdown options for dropdown 2 based on the selection of the option from dropdown 1.

#1488271

Well Minesh.
Actually I have this working fine for me on the search.

What I have now:
· Dropdown Field with 2 options
· Categories for option 1
· Categorias for option 2

I can show / hide the Categories depending on the values of the dropdown using this

 
		[wpv-conditional if="( '[wpv-search-term param='wpv-wpcf-tipo-de-empresa']' eq 'Profesional' )"]

[wpv-control-post-taxonomy taxonomy="categoria-guia-produccion" type="select" default_label="Todas las categorías" url_param="wpv-categoria-guia-produccion"]
      
[/wpv-conditional]
      		[wpv-conditional if="( '[wpv-search-term param='wpv-wpcf-tipo-de-empresa']' eq 'Empresa' )"]

Empresa
      
[/wpv-conditional]
      [wpv-conditional if="( '[wpv-search-term param='wpv-wpcf-tipo-de-empresa']' eq '' )"]
<label for="basic-url">      <font color="white">Seleccione</font></label>
      
[/wpv-conditional]

So, for me, the first issue is solved.
But now I found a problem in the "Add New Post form" related to this:

What I can't reach now is make the same hide/show in the "Add New Post Form".
I need to display the Categories 1 if user select Dropdown 1 and Categories 2 if select Dropdown 2.

Can you help me to do that?

Thanks Minesh for your patience!
🙂

#1488317

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Gald to know that you are able to make it work as per your requirement.

If you want to add the conditional display within the Toolset form, you should follow the following Doc:
=> https://toolset.com/documentation/user-guides/front-end-forms/cred-conditional-display-engine/

#1488357

Sorry Minesh, me again.
I've been working with the Doc you provided me.
But I'm not able to make this work.

Can you please check if my code is correct?

	<div class="col-sm-6">
      <label><h5>[wpml-string]Provincia *[/wpml-string]</h5></label>
[cred_field field='provincia' force_type='field' class='form-control' output='bootstrap']
  </div>
  </div>
      <div class="row">
	<div class="col-sm-12">
     
 [cred_show_group if="($(provincia) eq '1')" mode="fade-slide"]  
Show this content if 'Provincia' is set on 1
[/cred_show_group]
      [cred_show_group if="($(provincia) eq '2')" mode="fade-slide"]  
Show this content if 'Provincia' is set on 2
[/cred_show_group]

What I need to do is show content depending on the selection of field 'Provincia', but nothing is really happening.

Thanks a lot Minesh.

#1488361

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please share the problem URL where I can see the form.

#1488415

Yes, but I need to give you access. Can you please open a private ticket?

#1488421

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Sure.

I have set the next reply to private which means only you and I have access to it.

#1488447

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I checked on your install and I found that you are using outdated Toolset plugins. We always recommend running your site with the latest stable release plugin version.

*** Please make a FULL BACKUP of your database and website.***
Could you please update ALL Toolset plugins to it's latest officially released version. You can download the latest plugin release from your accounts page:
=> https://toolset.com/account/downloads/

Also, I see the JS errors on the browser's console, please disable all third party plugins one by one and check if there is any conflict with any thrid-party plugins you are using.

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