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
#402794
FireShot Capture 33 - Edit View ‹ Cars to find — WordPress_ - http___carfind.biz_wp-admin_admin.php.png

I am trying to: Sort two fields numerically

I visited this URL: hidden link

I expected to see: The numers sorted numericall 1,2,3,10,20,30,100,200,300

Instead, I got:not numericaly correct 1,10,100,2,20,200,3,30,300
I did look at minesh's solution on #375731 and tried to impliment it but then i get zero result in the min and max price search.

I tried this solution in the funtions.php which gave me the zero result listing

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;
}

The fact that i am getting a zero result tells me i am on the right path but i am messing something up.

I did remove the function at this stage as this is a live site and can not have a zero result.

I am attaching a screen print of the views screen also for ease of reference.

I do need the same solution on this page also.

hidden link

The id is 604
and the view name is
Multi Car View Private Search

Both views is from the same CPT and is just separated with a filter.

#402888

Shane
Supporter

Languages: Anglais (English )

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

Hi Andre,

Thank you for contacting our support forum.

It seems to me that you are trying to sort your view by a custom field correct?

If so then I would recommend that you take a look at the page below.
https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters

Your sort query is actually missing order parameter for whether ASC or DESC.

Please let me know if this helps.
Thanks,
Shane

#402978

HI Shane ,

It is being sorted asc. I am copying the code for the filter block underneath for you. Line 11 and line 12. search pcf lprice and pcf hprice in the code below. This issue relates specifically to the parametric search function high and low prices.

[wpv-filter-start hide="false"]
[wpv-filter-controls]
<div class="psrowformatingmaster">
<div class="psrowformating 1">
<div class="pcf brand">[wpml-string context="wpv-views"]Brand:[/wpml-string] [wpv-control field="brand" url_param="brand" type="select" auto_fill_default="Any brand" auto_fill="wpcf-brand" format="%%NAME%% (%%COUNT%%)" auto_fill_sort="asc"]</div>
<div class="pcf trans">[wpml-string context="wpv-views"]Transmission:[/wpml-string] [wpv-control field="transmision" url_param="transmision" type="select" auto_fill_default="Any transmission" auto_fill="wpcf-transmision" auto_fill_sort="asc"]</div>
<div class="pcf  fuel">[wpml-string context="wpv-views"]Fuel Type:[/wpml-string] [wpv-control field="fuel-type" url_param="fuel-type" type="select" auto_fill_default="Any fuel type" auto_fill="wpcf-fuel-type" auto_fill_sort="asc"]<br> </div>
  </div>
  <div class="psrowformating 2">
<div class="pcf brand>
<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>
<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>
[wpml-string context="wpv-views"]Styles:[/wpml-string] [wpv-control taxonomy="style" url_param="wpv-style" type="select" default_label="All Styles"]

[wpv-filter-reset reset_label="Reset" class="Reset" type="input"]
</div>
</div>

[/wpv-filter-controls]
[wpv-filter-end]
#403155

Shane
Supporter

Languages: Anglais (English )

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

Hi Andre,

I'm not quite sure I understand the specific issue.

What I can see is the view works fine. The issue is the items not being sorted by price.

But is it possible to explain with some screenshots ? If i understand the issue correctly then i'll be a much better help 🙂

Thanks,
Shane

#403301
dropdown.jpg

HI Shane ,

It is impossible to do a screen shot. I will try to explain it. When you go the hidden link screen on there website there is a parametric search function at the top . If you click on the low price drop-down function the first item in the search is for a value of 104900 as being the lowest price but there is a price 49900 in the list that should be at the top of the list because now it seems that the lowest price is way higher that the actual lowest price.

The third item in the list is for 1059900 and this should be way down as it is in the millions.

I understand the problem is that it sort the list in the following order 1,10,100,2,20,200,3,30.300 but i need it to sort 1,2,3,10,20,30,100,200,300.

The lowest value first and the highest value last

If you look at the support ticket #375731 it does explain it also and the answer given by Minesh to the problem. My problem is that when i implement that solution it removes all the values from my drop down and as such also all the results are also removed ending up with a null value query. i have managed t make a print-screen of the drop-down twirled open so you can see the values is not in largest to smallest

#403393

Shane
Supporter

Languages: Anglais (English )

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

Hi Andre,

Now I understand clearly, your values in the dropdown are not listed in numerical order as it should.

Would you mind providing me admin access to the website so that I can take a look at this through the backend ?

The private fields will be enabled for your next response.

Thanks,
Shnae

#403891

Shane
Supporter

Languages: Anglais (English )

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

Hi Andre,

Is this site a live site or a test site ?

If it is a live site then i would much rather create a test site for it so that I can perform various debug steps in order to see what the issue is.

Could you install the following plugin and create a duplicator package for me.
https://wordpress.org/plugins/duplicator/

Thanks,
Shane

#403948
FireShot Capture 34 - Packages ‹ Cars to find — WordPress_ - http___carfind.biz_wp-admin_admin.php.png

Hi Shane,

Unfortunately it is a live site. I have created the duplicator package and i have attached a screen print of the settings for you.

#403960

Hi Shane,

I am getting internal server 500 error when i try to create the duplicator. The plugin is installed and working. I have never worked with duplicator so i am not very confident about it. I have made a backup of the site so if you can try and see if you can make it work with duplicator you are more than welcome

#403977

Shane
Supporter

Languages: Anglais (English )

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

Hi Andre,

Could you let me know which version of php this server is currently running ?

Thanks,
Shane

#404026

Hi Shane

it i running on
5.4.45

#404219

Shane
Supporter

Languages: Anglais (English )

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

Hi Andre,

I would highly recommend that you contact your hosting provider and ask them to update you to at least php version 5.6 as this issue you are experiencing could be related to the php version you are currently running on.

Please try this and let me know if it helps.
Thanks,
Shane

#404558

good morning Shane,

I have created a duplicate development environment where you can work on without affecting the live setup. The url is hidden link

The login is the same as the live environment. One we have solved thsi problem i will just delete this setup.

#404830

Shane
Supporter

Languages: Anglais (English )

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

Hi Andre,

I'm not able resolve this issue by debugging, however I was able to work around it using some Javascript.

var selectList = jQuery('#wpv_control_select_price_min option');

selectList.sort(function(a,b){
    a = a.value;
    b = b.value;

    return a-b;
});

jQuery('#wpv_control_select_price_min').html(selectList);

var selectList = jQuery('#wpv_control_select_price_max option');

selectList.sort(function(a,b){
    a = a.value;
    b = b.value;

    return a-b;
});

jQuery('#wpv_control_select_price_max').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('#wpv_control_select_price_min option');

selectList.sort(function(a,b){
    a = a.value;
    b = b.value;

    return a-b;
});

jQuery('#wpv_control_select_price_min').html(selectList);
  
  	var selectList = jQuery('#wpv_control_select_price_max option');

selectList.sort(function(a,b){
    a = a.value;
    b = b.value;

    return a-b;
});

jQuery('#wpv_control_select_price_max').html(selectList);
});

Add the above to the js editor of your view and this should sort our field values correctly

Please let me know if this helps.
Thanks,
Shane

#404849

HI Shane,

That worked 100% but now the list does not show unique reference anymore. Ie The same price is now repeating twice for each price

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