This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Taxonomy archive search

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #18112
    dpersson87dpersson87
    Participant

    Hello,

    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,
    Daniel

    #18120
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Hi 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:

    #18121
    dpersson87dpersson87
    Participant

    Works 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,
    Daniel

    #18123
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Hi 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]

    #18126
    dpersson87dpersson87
    Participant

    You cannot access this content.

    #18127
    Ernest MarcinkoErnest Marcinko
    Keymaster

    You cannot access this content.

    #18128
    dpersson87dpersson87
    Participant

    You cannot access this content.

    #18129
    Ernest MarcinkoErnest Marcinko
    Keymaster

    You cannot access this content.

Viewing 8 posts - 1 through 8 (of 8 total)
  • The topic ‘Taxonomy archive search’ is closed to new replies.