Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Fronted Search Setting options [esclude terms empty]
- This topic has 6 replies, 2 voices, and was last updated 9 years, 7 months ago by
Ernest Marcinko.
-
AuthorPosts
-
October 10, 2016 at 11:53 am #10415
K15Lmk98
ParticipantThis is an automatic translation
Good day,
Frontend Search Settings > Categories & Taxonomy Terms, i added the taxonomy “luoghi” with over 1000 terms. – see screenshot1 –
It is possible, perhaps through a filter to exclude all empty terms, and leave only those who post?
Thanks, Claudio_
October 10, 2016 at 12:04 pm #10417Ernest Marcinko
KeymasterHi Claudio!
It is actually possible with a filter. Use this code for your case to filter the “luoghi” taxonomy:
[php]add_filter( ‘asp_fontend_get_taxonomy_terms’, ‘asp_filter_empty_terms’, 1, 3 );
function asp_filter_empty_terms($terms, $taxonomy, $args) {
if ( $taxonomy == ‘luoghi’ ) {
return get_terms($taxonomy, array(
‘orderby’ => $args[‘orderby’],
‘order’ => $args[‘order’],
‘taxonomy’=> $taxonomy,
‘hide_empty’ => 1
));
}
return $terms;
}[/php]October 10, 2016 at 12:31 pm #10418K15Lmk98
ParticipantHi Ernest,
Thanks for the filter.
I just wanted to take the term parent, and I modified the code with ‘parent’ => 0:[code]add_filter( ‘asp_fontend_get_taxonomy_terms’, ‘asp_filter_empty_terms’, 1, 3 );
function asp_filter_empty_terms($terms, $taxonomy, $args) {
if ( $taxonomy == ‘luoghi’ ) {
return get_terms($taxonomy, array(
‘orderby’ => $args[‘orderby’],
‘order’ => $args[‘order’],
‘taxonomy’=> $taxonomy,
‘parent ‘ => 0,
‘hide_empty’ => 1
));
}
return $terms;
}[/code]But strangely always returns the children – see screnshot –
You have a solution?
Thanks, Claudio_
October 10, 2016 at 12:42 pm #10420Ernest Marcinko
KeymasterHi,
The parent =>0 parameter works on my test environment, it only displays parent elements, so I don’t know what is wrong.
If you want, you can provide temporary log-in and FTP and I can take a look.
October 10, 2016 at 1:10 pm #10421K15Lmk98
ParticipantHi Ernest,
in fact it is really strange. I disabled some plugins that could interfere with ASP, but the result does not change.
I’m developing locally.
When I publish the site I send accesses.Thanks, Claudio_
October 10, 2016 at 4:43 pm #10422K15Lmk98
ParticipantHi Ernest,
This is a machine translation.
Like I said, it is strange that ‘parent’ => 0 does not work.
However I want to share the solution I found, if other users had my need.
[code]add_filter( ‘asp_fontend_get_taxonomy_terms’, ‘asp_filter_empty_terms’, 1, 3 );
function asp_filter_empty_terms($terms, $taxonomy, $args) {
if ( $taxonomy == ‘luoghi’ ) {
$terms = get_terms($taxonomy, array(
‘orderby’ => $args[‘orderby’],
‘order’ => $args[‘order’],
‘taxonomy’=> $taxonomy,
‘parent ‘ => 0,
‘hide_empty’ => 1
));
foreach ($terms as $key =>$singleTerm) :
$term = get_term_by(‘id’, $result->term_id, $taxonomy);
if ( $singleTerm->parent != 0 ) :
unset($terms[$key]);
endif;
endforeach;
return $terms;
}return $terms;
}[/code]Ticket chiuso. Thanks for the support, Claudio_
October 11, 2016 at 8:15 am #10425Ernest Marcinko
KeymasterYou cannot access this content.
-
AuthorPosts
- The topic ‘Fronted Search Setting options [esclude terms empty]’ is closed to new replies.