Skip Navigation

[Résolu] Not doing search of value field numeric correctly

This support ticket is created Il y a 7 années et 11 mois. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 30 réponses, has 2 voix.

Last updated by AndreG3332 Il y a 7 années et 10 mois.

Assisted by: Shane.

Auteur
Publications
#404884

Shane
Supporter

Languages: Anglais (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Andre,

Thats strange because I tried the exact same code on this page and it worked flawlessly.
hidden link

Thanks,
Shane

#405459
low-price.jpg

Hi Shane,

I have been playing around and i am still not able to get the amount to reflect as unique amounts as above. In the process i have tried something and the answer may lie in that to solve the problem.

The code for the min and max amount on the live system is as follow:

Min amount

 <div class="pcf lprice">[wpml-string context="wpv-views"]Low Price (R):[/wpml-string] [wpv-control field="price" url_param="price_min" type="select" auto_fill_default="Any price" auto_fill="wpcf-price" auto_fill_sort="asc"]</div>

Max amount

<div class="pcf hprice">[wpml-string context="wpv-views"]High Price (R):[/wpml-string] [wpv-control field="price" url_param="price_max" type="select" auto_fill_default="Any price" auto_fill="wpcf-price" auto_fill_sort="asc"]</div>

You code for the min amount is:

[wpv-control field="price" url_param="price_min" type="select" auto_fill_default="Any price" auto_fill="wpcf-price" auto_fill_sort="asc"][wpml-string context="wpv-views"]Price (R):[/wpml-string]

So to see what the effect would be if i copied your code into the live system and it doubled it again. as can be seen by the attached screen shot. The screen shot is with your code above.

The js works 100% it seems there is something else that is causing the duplication of values.

#405512

Shane
Supporter

Languages: Anglais (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Andre,

I believe i've found the issue 🙂

It seems you have the mobile version of the view on the same page as well. This seems to be causing the issue because if the names of the filters are the same then the javascript will pick up those values as well.

So what you can try is to temporarily remove the mobile version and see if the issue is still there.

Thanks,
Shane

#405681

HI Shane,

This thing is going to drive me to drink! You are 100% correct when I delete the mobile version it does clear it duplication problem.

However now suddenly it is defaulting to a price and it will only search for that one price. It did work yesterday when i wrote the above message.

Nothing has changed as far as i can see.

The second issue now obviously is how will I solve my responsive problem if a second view doubles my prices? I am using a different approach for my responsive settings.

#405850

Shane
Supporter

Languages: Anglais (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Andre,

Is it possible to replicate this issue on the test site so I can have a look ?

Looking forward to hearing from you soon.

Thanks,
Shane

#405893

HI Shane.

Yes i did manage to replicate it in the test site. As soon as i copied the js code into the view "Multi Car View Search" it had that effect. I just deleted the js script from the live site now the list is working again but now obviously the numbering sequence is not working now again.

What id also noted is that even if the mobile view is there there is no duplication again. So somehow the js is causing both the filter not to work and the duplication of the values. in conjunction with the mobile view.

#405895

HI Shane.

Yes i did manage to replicate it in the test site. As soon as i copied the js code into the view "Multi Car View Search" it had that effect. I just deleted the js script from the live site now the list is working again but now obviously the numbering sequence is not working now again.

What id also noted is that even if the mobile view is there there is no duplication again. So somehow the js is causing both the filter not to work and the duplication of the values. in conjunction with the mobile view.
Something else i noted just now is that the values in excess of 1 mill is still not sorting correctly either. They are interspersed between the other numbers.

Looking back at my very first post on this matter i quoted a message by minesh where he was working on a similar case and he used a php function to solve this. Would that not maybe be a better possible option in this matter?

The message number is #375731

#405901

Shane
Supporter

Languages: Anglais (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Andre,

I believe that you are referring to this code here correct ?

add_filter( 'wpv_filter_query', 'hook_search_custom_fields', 10, 2 );
function hook_search_custom_fields( $query_args, $view_settings ) {
      
if($view_settings['view_id'] == 167)  {   
    $query_args['orderby'] = array( 'meta_value_num');
    $query_args['meta_key'] = 'price'; 
    $query_args['meta_type'] = 'numeric'; //
        
  }    
return $query_args;
}

Also I believe that it is better to perform the sorting of the items through the frontend using javascript rather than a hook.

The reason is that the only hooks we have are filter hooks and they are meant to impact of the view results being displayed and not the filters.

Could you point me to the page on the test site where the issue is replicated?

Thanks,
Shane

#405904

HI Shane.

Ah ok i understand.

Here is the page url
hidden link

#405926

Shane
Supporter

Languages: Anglais (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Andre,

I have some good news 🙂

I was able to allow you to have the mobile view on the page along with the full size view without repeating the values.

What I did was to assign classes to the filters and then use the javascript to connect to the classes instead of using the ids

[wpml-string context="wpv-views"]Low Price (R):[/wpml-string] [wpv-control field="price" class=" Lower-price" url_param="price_min" type="select" auto_fill_default="Any price" auto_fill="wpcf-price" auto_fill_sort="asc"]</div>
<div class="pcf hprice">[wpml-string context="wpv-views"]High Price (R):[/wpml-string] [wpv-control field="price" url_param="price_max" class=" Upper-price" type="select" auto_fill_default="Any price" auto_fill="wpcf-price" auto_fill_sort="asc"]</div>

I then changed the code to the following.

var selectList = jQuery('.Lower-price option');
 
selectList.sort(function(a,b){
    a = a.value;
    b = b.value;
 
    return a-b;
});
 
jQuery('.Lower-price').html(selectList);
 
var selectList = jQuery('.Upper-price option');
 
selectList.sort(function(a,b){
    a = a.value;
    b = b.value;
 
    return a-b;
});
 
jQuery('.Upper-price ').html(selectList);
jQuery( document ).on( 'js_event_wpv_parametric_search_triggered', function( event, data ) {
    /**
    * data.view_unique_id (string) The View unique ID hash
    * data.form (object) The jQuery object for the View form
    * data.force_form_update (bool) (optional) Whether the View settings force to update the form after a change
    * data.force_results_update (bool) (optional) Whether the View settings force to update the results after a change
    */
    var selectList = jQuery('.Lower-price option');
 
selectList.sort(function(a,b){
    a = a.value;
    b = b.value;
 
    return a-b;
});
 
jQuery('.Lower-price').html(selectList);
   
    var selectList = jQuery('.Upper-price option');
 
selectList.sort(function(a,b){
    a = a.value;
    b = b.value;
 
    return a-b;
});
 
jQuery('.Upper-price').html(selectList);
});

You can see the live demo here.
hidden link
Please let me know if this helps.

Thanks,
Shane

#405996

HI Shane,

i see what you did with the classes and that is very cleaver to separate the two views Especially as i do have two more simelar views just for a different results.

Multi Car View Private Search and Multi Car View Private Search mobile.

They are just to give a different search results. All vehicle are either private or dealership vehicle. So the one wee have ben working on are dealership and these ones are private owned vehicles. The views as identical obviously except for the filter on dealership or private.

I don't know if they may be impacting this also. I will add the extra classes to that one also to ensure that we don't sit with further duplication. Obviously i will have to alter the java scrip to accommodate for that also if i am not wrong?

I used your code but it is still not sorting by value large to small. it is still sorting starting with the first number. what the original problem was. I check on the development and life site and both is giving the same results. and the results are also not with in the search criteria parameters. Ie is is search between 102000 and 122000 the results is outside that scope.

#406122

Shane
Supporter

Languages: Anglais (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Andre,

I made some small changes to the code.

It should sort properly now.
hidden link

Please have a look and let me know if everything is ok.

Thanks,
Shane

#406174

Hi Shane,

I do believe there is reason to crack open that bottle of champagne! You seemed to have solved this problem. I would just like to keep this open for another day or two to make sure a van replicate the solution in the private and mobile search options also!

I really appreciate your assistance with this matter!

#406254

Hi Shane,

That code worked and I do believe I did solve the mobile issue by adding the term mobile to the class and changed the js code you gave me accordingly.

There is however one more issue that has cropped up after all this. The search works 100% the first time. When you do a search and try to do a subsequent search the values changed back to the original format.

I have updated the development site with the latest coding for you to look at.

#406701

Shane
Supporter

Languages: Anglais (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Andre,

This is a simple fix 🙂

All that was needed was to change the callback function that was being used to run the script after the search results have been fully updated.

It should be working now, It did when I test it 🙂

Please have a look and let me know.
Thanks,
Shane

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.