Skip Navigation

[Resolved] Parent category / taxonomy

This thread is resolved. Here is a description of the problem and solution.

Problem:

Show "Alle" term posts always in the search results.

Solution:

You can show the "Alle" posts always by using filter hook "wpv_filter_query", for example:

https://toolset.com/forums/topic/parent-category-taxonomy/#post-1978117

Relevant Documentation:

https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

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.

Our next available supporter will start replying to tickets in about 6.72 hours from now. Thank you for your understanding.

This topic contains 14 replies, has 2 voices.

Last updated by maiS 1 month ago.

Assigned support staff: Luo Yang.

Author
Posts
#1966049

Hi there,
During our Create Camp post form the host of the camp needs to choose what ages and levels the camp cover. 1 of the possible taxonomies says "all" - in case the camp literally is for everyone. But if i then search for a specific age, the "all" taxonomy does not appear - and it should, because "all" also covers this specific age and level group. So basically all taxonomies should cover

1) the specific age and level
2) the "all" category

Can you help? Thanks

#1966333

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

all-option.JPG

Hello,

I assume you are going display an "All" option in the taxonomy field of View block search form.

If it is, you don't need to setup the "All" term in the custom taxonomy, you can add "All" option in search form directly, for example:
Edit the page "Badminton Camps":
hidden link

find and select Custom Search Filter block "Alder og Niveau", in section "Field Settings", option "Label for the first 'default' option", fill text: All.

See my screenshot: all-option.JPG

#1967203

So if I choose "U11A" as age and level will the results then display the camps within "U11A" AND "All"? That is what i am going for.

#1967563

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Yes, you are right, please let me know you need assistance to setup it in your website.

#1969067

Hi Lou,
I followed your guide and set the default value to "all" but if i then choose for example U11A i only get the camps that have the taxonomy U11A - not the camps "All".

The result need include both:
U11A
ALL

If I choose U13M i need the results to include:
U13M
ALL

etc.

#1970141

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

all-option3.JPG
all-option2.JPG

I have done below modifications in your website:
Edit the page:
hidden link
Find and select fields "Lokationer" and "Alder og Niveau" in the custom search form, in the sidebar of block setting, fill value "All" in option "abel for the first 'default' option", see my screenshot all-option2.JPG

Test it in front-end:
hidden link
field "Alder og Niveau" Choose option "U11A", submit the form
click field "Alder og Niveau" field again, I can see the option "All" without any problem, see my screenshot all-option3.JPG

#1971433
screenshot-3.png
screenshot-2.png
screenshot-1.png
screenshot 4.png

Hi Lou,

I don't think we are talking about the same thing - I am talking about the search results. I made 4 screenshot.

1) I search for "all"
2) I get all camps = good
3) Now i search for U11A
4) I only get the U11A camps and not the All camps also. I need the "All" taxonomi to show up in all results no matter if you choose All or U11A or U13M or whatever. If you only choose All - then only 1 taxonomy appears in the search result. If you search for U11A then 2 taxonomies show up in the search results: "U11A" + "All".

#1971771

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Thanks for the details, in this case, you need to edit each "camp" post:
hidden link

and add "All" term into taxonomy "Alder og Niveau", so it will display in the search filter and display in the search result too.

#1977607

Hi Lou,

I can finally answer this ticket! Thank god!

The term "all" is already there - it is called "alle". But is there a way to combine the taxonomy "All / Alle" with all the other taxonomies? So that the camps with "All / Alle" chosen gets shown in the results no matter what?

#1978117

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

There is a misunderstanding, you don't need to add "All" term into taxonomy "alder-og-niveau".

You can show the "Alle" posts always by using "wpv_filter_query", I have done below modifications in your website:
Dashboard-> Toolset-> Settings-> Custom code
Add one item "show-alle-posts":
hidden link

with below codes:

add_filter( 'wpv_filter_query', 'show_alle_posts_func', 10,3 );
function show_alle_posts_func( $query_args, $view_settings, $views_id ) {
    if ( $views_id == 2269 ) { // if it is specific view and by default
        if(isset($query_args['tax_query'])){
        	foreach($query_args['tax_query'] as $k => $v){
              	if($v['taxonomy'] == 'alder-og-niveau'){
                  	$query_args['tax_query'][$k]['terms'][] = 102; // 102 is term ID of "alle"
                  	break;
                }
            }
        }
    }
    return $query_args;
}

Please test again, check if the problem is fixed, thanks

#1979791

Hi Lou,

Wow thanks but the function doesnt seem to work at my end. If i choose the category U11A i still only get the 2 U11A Camps from the U11A category and not category: U11A + category: All

#1980453

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

You are display the search form in with post view (ID 1497), so I have changed this line 12 of the custom codes to:

if ( in_array($views_id, array(1497)) ) { // if it is specific view and by default

Please test again, check if it is fixed, thanks

#1981363

Oh my god I think it works!!! Thank you so much!

#1981537

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Please update here if you need more assistance for it, thanks

#1987275

My issue is resolved now. Thank you!