WordPress.org

Ready to get started?Download WordPress

Forums

Ultimate WP Query Search Filter
Include instead of Exclude? (15 posts)

  1. NeoBean
    Member
    Posted 4 months ago #

    This is an awesome plugin! Thanks for all of your hard work on it :]

    I'm wondering how to use Include instead of Exclude, as in, if I have 100 categories but only want to include 5. Or in my case, I want to have 3 different versions of the search form, each including only about 10 categories.

    Using Exclude in this scenario is less than ideal for 2 reasons:

    1) it would be much easier to enter 5 ids to include, than 95 to exclude
    2) when I add new categories, I have to go back in and add the new categories to the Exclude list :(

    I've tried editing the code myself but couldn't figure it out. I duplicated the exclude functions and changed the variables, adjusted what I could find, but no result. Is there something I'm missing, or could this be added to a future release by any chance? :)

    (Also, there's a minor typo- the Admin section says "Exculde" instead of "Exclude". I noticed this in some of the variables as well. Only seen by Admins so not a big deal)

    Thanks for your help!

    https://wordpress.org/plugins/ultimate-wp-query-search-filter/

  2. TC.K
    Member
    Plugin Author

    Posted 4 months ago #

    Hi,
    You can use 'uwpqsf_taxonomy_arg' for changing the parameter. The plugin use get_terms() to get all the taxonomy fields. So, any parameter that supported by get_terms(), also can be use for uwpqsf_taxonomy_arg().

    Eg.

    add_filter('uwpqsf_taxonomy_arg','include_wpsqf_term','',2);
    function include_wpsqf_term($args,$formid){
      $args['exclude']='';//clear any exclude term id if there any
      $args['include'] = array('1,2,3,4,5');//include all the term id you want to add.
    
      return $args;
    }

    When you use this, note that it will interfere with the 'search all' query. So, it is advice not to use 'search all' for the field.

  3. NeoBean
    Member
    Posted 4 months ago #

    Thank you so much! That works- I just had to remove both of the ' apostrophes from the include array list. So for others wondering, it should be:

    $args['include'] = array(1,2,3,4,5);

    Last question- to use this with multiple forms, I tried using the $formid parameter but without luck. I tried adding:

    $formid = [your_id_here];

    on the line before the return statement, and duplicating the function and filters then using a different $formid and renaming the function, but no luck (it just uses the second function I create, probably because I'm reusing the same filter). Any advice?

    Thanks again :)

  4. TC.K
    Member
    Plugin Author

    Posted 4 months ago #

    where did you use the $formid?

  5. NeoBean
    Member
    Posted 4 months ago #

    I used it in the function, right before

    return args;

    as well as tried passing it in directly in the parameter, like

    function include_wpsqf_term($args,800){

    And neither seemed to work.

  6. TC.K
    Member
    Plugin Author

    Posted 4 months ago #

    give me your full code.

  7. NeoBean
    Member
    Posted 4 months ago #

    Sorry for the delay, here it is-

    add_filter('uwpqsf_taxonomy_arg','include_wpsqf_term','',2);
    function include_wpsqf_term($args,$formid){
    $args['exclude']='';//clear any exclude term id if there any
    $args['include'] = array(156,157,160,161,159,158);//include all the term id you want to add.
    $formid = 779;
    return $args;
    }

    However, even with only one of these blocks (i.e., removing the formid altogether and only using one form) it messes up the other taxonomies I add. So if I try to "include" categories but also allow for custom taxonomies or tags, they only show up as "checkbox"

    Thanks for your help!

  8. TC.K
    Member
    Plugin Author

    Posted 4 months ago #

    try this

    function include_wpsqf_term($args,$formid){
    if($formid == '779'){
    $args['exclude']='';//clear any exclude term id if there any
    $args['include'] = array(156,157,160,161,159,158);//include all the term id you want to add.
    }
    return $args;
    }
  9. NeoBean
    Member
    Posted 4 months ago #

    Hmm, for some reason that doesn't work at all- all categories are displayed, not just the ones I tried to include.

    I don't have any exclusions set, not that it would matter since they'd be cleared anyway.

    You know, we could take this in another direction...when I use:

    add_filter('uwpqsf_taxonomy_arg','include_wpsqf_term','',2);
    function include_wpsqf_term($args,$formid){
    $args['exclude']='';//clear any exclude term id if there any
    $args['include'] = array(156,157,160,161,159,158);//include all the term id you want to add.
    return $args;
    }

    The inclusion works, but any other taxonomies I add just render as "checkbox checkbox checkbox". If we could solve the multiple taxonomy issue, I would probably be OK just having one form.

  10. TC.K
    Member
    Plugin Author

    Posted 4 months ago #

    I see,
    So you have multiple taxonomies in one form. The above script wont work.

    The filter 'uwpqsf_taxonomy_arg' so far can't do that. But I will include taxonomy slug as another parameter to the filter in the future update. With this new parameter you can conditionally include the term ids by each taxonomy slug.

    However, not sure the update date yet. Hopefully can get it done by this month.

  11. NeoBean
    Member
    Posted 4 months ago #

    Awesome, thank you! I really appreciate it :]

  12. aptharsia
    Member
    Posted 4 months ago #

    Just wanted to say, I hope that include rather than exclude is an option for a future update, especially if using multiple taxonomies in one form.

  13. my_2_cents
    Member
    Posted 3 months ago #

    Awesome plugin, really really useful. Include would be amazing, if you choose the tags taxonomy INCLUDE would be a lot better than EXCLUDE. I don't mind at all paying for such an update, it would be extremely useful :)

    Thank you kindly and keep up the awesome work,
    Chris

  14. my_2_cents
    Member
    Posted 3 months ago #

    If I wanted to opt for INCLUDE, where would I need to paste the code you provided in the second post?

    add_filter('uwpqsf_taxonomy_arg','include_wpsqf_term','',2);
    function include_wpsqf_term($args,$formid){
      $args['exclude']='';//clear any exclude term id if there any
      $args['include'] = array('1,2,3,4,5');//include all the term id you want to add.
    
      return $args;
    }

    Thank you kindly,
    Chris

  15. TC.K
    Member
    Plugin Author

    Posted 3 months ago #

    In your theme functions.php

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.