WordPress.org

Ready to get started?Download WordPress

Forums

Ajax WP Query Search Filter
[resolved] Results with multiple taxonomies not accurate (20 posts)

  1. Aldo
    Member
    Posted 1 year ago #

    Hello

    I have a taxonomy "types". When checking two terms in the search form, the results are not accurate, as it shows me as well entries containing only one of the two selected terms.

    It should list results only containing both terms.

    Any idea?

    Thanks,
    Aldo

    http://wordpress.org/extend/plugins/ajax-wp-query-search-filter/

  2. TC.K
    Member
    Plugin Author

    Posted 1 year ago #

    Have you check on the 'OR' boolean relationship in the form setting page?

  3. Aldo
    Member
    Posted 1 year ago #

    No, AND is selected.

  4. TC.K
    Member
    Plugin Author

    Posted 1 year ago #

    I think you have misunderstood the plugin boolean relationship. It is use to compare each of the of the taxonomy, not taxonomy's term.
    Eg.
    type AND type2 AND type3....

    not
    type
    -term AND term2
    type2
    -term3 AND term4

  5. Aldo
    Member
    Posted 1 year ago #

    Ok. so lets say I have a taxonomy "Mailing-Options" with three terms:
    - Customers
    - Friends
    - Family

    Now I would like to check Friends and Familiy, to get all the entries who have BOTH terms associated.

    Is this possible?

  6. TC.K
    Member
    Plugin Author

    Posted 1 year ago #

    No, it will search the post with "Friend" and with "Family"

  7. Aldo
    Member
    Posted 1 year ago #

    Is there a way to add an option who generates the query in the background so all terms match?
    http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters

  8. TC.K
    Member
    Plugin Author

    Posted 1 year ago #

    Yes, you can. I have the filter for this - ajwpqsf_get_taxo()
    Example:

    add_filter('ajwpqsf_get_taxo', 'new_query', '' ,3);
    function new_query($taxo,$id, $gettaxo){
       $taxo[] = array(
    		'taxonomy' => 'product_cat',
    		'field' => 'slug',
    		'terms' => 'new-arrival',
    		'operator' => 'IN'
      	);
    	return $taxo;
    }
  9. Aldo
    Member
    Posted 1 year ago #

    Ok, lets say I have a taxonomy with "mailing-options", with the terms "christmas" and "easter".
    How would the function look like to check for both terms?

    Previously we created the form containing the checkboxes for the taxonomy with your plugin.

    Thanks!
    Aldo

  10. TC.K
    Member
    Plugin Author

    Posted 1 year ago #

    I don't think so. If you created in the plugin, then it will automatically handle by the plugin.

  11. Aldo
    Member
    Posted 1 year ago #

    Would it be an option to extend your plugin so that you could set the boolean relationship between the taxonomy terms queries to AND, OR and so on?
    This would be a great addon!

  12. Aldo
    Member
    Posted 1 year ago #

    I managed to make the changes in your plugin.
    Maybe you can give me a feedback if there are any potential issues:

    In process.php a changed the following:
    After line 136 added
    , 'operator' => 'AND'

    After line 144 added
    , 'operator' => 'AND'

    In line 183 removed:
    && empty($keyword)

    As I mentioned before, it would be great if in the WP backend of your plugin we could set the operator between the taxonomy terms.

    Regarding the change on line 183 I'm not sure if it breaks anything.

  13. TC.K
    Member
    Plugin Author

    Posted 1 year ago #

    If you do this, all your taxonomies terms will behave with the AND boolean relationship. It is fine if you have only one search form, but if you have other search form to create, then this could be an issue. Also, you will have to change this every time you update the plugin.

    Actually you can set the changes without making any changes on the plugin file by using the filter ajwpqsf_get_taxo().

    Example is at here.

  14. Aldo
    Member
    Posted 1 year ago #

    Thanks for your feedback.
    I get to warnings using your hook:
    Warning: Missing argument 2 for my_custom_process() in /home/interpub/www/dev.site.com/wp-content/themes/interface/functions.php on line 191
    Warning: Missing argument 3 for my_custom_process() in /home/interpub/www/dev.site.com/wp-content/themes/interface/functions.php on line 191

    The affected line is:
    function my_custom_process($taxo,$id, $gettaxo ){

  15. TC.K
    Member
    Plugin Author

    Posted 1 year ago #

    Oh yes, need to defined the number of arguments for the hook.
    Try this
    add_filter('ajwpqsf_get_taxo','my_custom_process','' 3);

  16. Aldo
    Member
    Posted 1 year ago #

    Works perfect :-) Thanks!

    Last thing, line 183 in process.php:
    && empty($keyword)

    I removed this to have it strict, so the search string and the terms are checked.
    Any way to manipulate this through a hook?

  17. TC.K
    Member
    Plugin Author

    Posted 1 year ago #

    Oh..I forgot to add a filter on this. Maybe will add it in next release.

  18. Aldo
    Member
    Posted 1 year ago #

    Would be great ;-)

    Thanks for all your help.

  19. TC.K
    Member
    Plugin Author

    Posted 1 year ago #

    Hi, just to let you know that I already added the filter for taxonomy and meta filed query filter, before adding to the wp_query argument.

    They are barg_tax_query for taxonomy and 'barg_meta_query' for meta field.
    To use it, fore example for taxonomy query:

    add_filter('barg_tax_query','new_text_query','', 3);
    function new_text_query($tax_query, $get_tax, $keyword)
    {
    $tax_query = '';
    $tax_query = isset($get_tax)  ? $get_tax : null;
    return $tax_query;
    }
  20. Aldo
    Member
    Posted 12 months ago #

    Thanks!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.