P
P
Programmir2021-06-29 10:36:17
WordPress
Programmir, 2021-06-29 10:36:17

How to speed up selection in wordpress?

add_action( 'pre_get_posts', 'my_change_sort_order'); 
function my_change_sort_order($query){
   if(!is_admin() && $query->is_main_query() ){
    if($query->is_archive){
      $query->set('orderby', 'meta_value_num');	
      $query->set('meta_key', 'product_quantity');	 
      $query->set('order', 'DESC'); 
    }
}
}

You must first select the goods that are in stock. But the selection takes a very long time, about ten seconds, sometimes the page does not even load. How can you speed up sampling?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Arkhipov, 2021-06-29
@IgorArkhipov

in theory, you can add an index in the database (of course, they are there , but not by custom properties)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question