Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Taxonomy archive search
- This topic has 7 replies, 2 voices, and was last updated 8 years ago by
Ernest Marcinko.
-
AuthorPosts
-
June 4, 2018 at 10:47 am #18112
dpersson87
ParticipantHello,
Im trying to figure out how to add a search to my taxonomy archive, I want it to search from my custom post type but only in the currently showing category (taxonomy) archive.
This is what Im trying:
[code]function asp_query_args_change($args, $search_id) {
$id = get_queried_object_id();
$tax = get_queried_object()->term_name;if ($search_id == 3) {
$args[‘post_tax_filter’] = array(
array(
‘taxonomy’ => $tax,
‘include’ => array($id)
)
);
}
return $args;
}add_filter("asp_query_args", "asp_query_args_change", 1, 2);[/code]
But it doesnt work, however this works:
[code]function asp_query_args_change($args, $search_id) {
if ($search_id == 3) {
$args[‘post_tax_filter’] = array(
array(
‘taxonomy’ => ‘my-tax-name’,
‘include’ => array(2)
)
);
}
return $args;
}add_filter("asp_query_args", "asp_query_args_change", 1, 2);[/code]
But ofcourse I want it to be dynamic and always only include posts from my custom post type that im currently watching.
Thanks,
DanielJune 5, 2018 at 10:50 am #18120Ernest Marcinko
KeymasterHi Daniel,
The get_queried_object_id() is not going to work in that context, as within an ajax request there is no information about the page/post ID nor the WP_Query where the request is originated from.
I think the only solution is to use an additional snippet to store the queried object ID as an input, that is then passed as an option, then use that as the argument in a separate filter:
June 5, 2018 at 10:59 am #18121dpersson87
ParticipantWorks perfectly, thank you!
Maybe you can answer why my jquery click events dont work on my vertical results aswell (im using a 100% customized vertical.php)? The links inside works, but not when I try to make a div clickable.
Thanks,
DanielJune 5, 2018 at 12:00 pm #18123Ernest Marcinko
KeymasterHi Daniel,
That is impossible to tell without seeing your custom code, and even then it might be problematic.
One thing you have to make sure, is that the event handlers need to be attached dynamically, as the result list updates on every ajax request, and previous handlers get detached.
Something like this:[html]$(‘.asp_r’).on(‘click’, ‘.asp_content’, function(){ // your code });[/html]
June 5, 2018 at 12:19 pm #18126dpersson87
ParticipantYou cannot access this content.
June 5, 2018 at 12:23 pm #18127Ernest Marcinko
KeymasterYou cannot access this content.
June 5, 2018 at 12:42 pm #18128dpersson87
ParticipantYou cannot access this content.
June 5, 2018 at 12:58 pm #18129Ernest Marcinko
KeymasterYou cannot access this content.
-
AuthorPosts
- The topic ‘Taxonomy archive search’ is closed to new replies.