Modify WHERE clause

This topic contains 8 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 3 years, 4 months ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #30410
    hbb97
    hbb97
    Participant

    Hello

    I have a project with huge customization.

    I am using these filters:

    add_filter(‘posts_join’, ‘custom_filter_posts_join’ );
    add_filter( ‘posts_where’, ‘custom_filter_posts_where’, 10, 2 );

    Is posible to do that with your API of filters and Hooks? As I readed is not so clear, I think is not posible…

    Thanks
    Héctor

    • This topic was modified 3 years, 5 months ago by hbb97 hbb97.
    #30421
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi Héctor,

    You can add fields to the final query, there are multiple ways, these are not documented yet unfortunately. I recommend using these hooks:

    $add_select = apply_filters('asp_cpt_query_add_select', '', $args, $phrase, $phrase_array);
    $add_join = apply_filters('asp_cpt_query_add_join', '', $phrase, $phrase_array);
    $add_where = apply_filters('asp_cpt_query_add_where', '', $phrase, $phrase_array);

    You can add a hook to them like so:

    add_filter('asp_cpt_query_add_join', 'my_asp_cpt_query_add_join', 10, 4);
    function my_asp_cpt_query_add_join($query, $args, $phrase, $phrase_array) {
    	global $wpdb;
    	// Return the join query you want
    	return "LEFT JOIN ...";
    }
    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #30429
    hbb97
    hbb97
    Participant

    Great!!

    That filters are good for Search Engine = Regular Engine.
    Is something equivalent for Search Engine = Index Table Engine?

    Thanks
    Héctor

    #30437
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Sure, sorry I forgot about that:

    apply_filters('asp_it_query_add_select', '');
    apply_filters('asp_it_query_add_join', '');
    apply_filters('asp_it_query_add_where', '');

    Please note that the index table engine uses a completely different query on a different tabe, so to get the fields you need I recommend checking line 350-398 in wp-content/plugins/ajax-search-pro/includes/classes/search/class-asp-search-indextable.php

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #30446
    hbb97
    hbb97
    Participant

    Is posible to get inside that filters, $args variable, or search phrase?

    #30452
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hm, I think not without changes to the core. It looks like I forgot to add those arguments to the filters.
    Anyways, I will definitely fix that in the upcoming release, but until then, you can fix that by replacing one of the plugin files:

    1. Open up the wp-content/plugins/ajax-search-pro/includes/classes/search/class-asp-search-indextable.php file on your server.
    2. Replace it’s contents with this
    3. Save

    Now you should be able to use the same arguments as on the regular engine (query, $args, $phrase, $phrase_array)

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #30466
    hbb97
    hbb97
    Participant

    Hello

    Going to test filters for Indexed Table Search, but:

    Is posible to add registers at Index Creation?
    Are some actions or filters involved at that point?

    Thanks
    Héctor

    #30470
    hbb97
    hbb97
    Participant

    With this filters it works for me:

    $values = apply_filters( ‘asp_post_custom_field_before_tokenize’, $values, $the_post, $field );

    Thanks!
    Héctor

    #30472
    Ernest Marcinko
    Ernest Marcinko
    Keymaster
    You cannot access this content. Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.