$postids = $wpdb->get_results(" SELECT p.ID FROM g5t_posts p JOIN g5t_postmeta p2 ON p.ID=p2.post_id JOIN g5t_postmeta p3 ON p.ID=p3.post_id WHERE (p2.meta_key = 'sticky' AND p2.meta_value = '1' AND p3.meta_key = 'sticky_date' AND DATE_ADD(p.post_modified, INTERVAL + p3.meta_value DAY) >= NOW()) AND p.post_status = 'publish' ORDER BY p2.meta_value DESC, p.post_date DESC LIMIT $limit_posts ");//Запрос на вывод закрепленных постов 

Is it possible to somehow optimize the query? Or convert it to wp_query. If there is something terribly illiterate, please indicate

  • one
    And what did not suit with wp_query.? Why this garden? - SeVlad
  • So how to collect it in wp_query? - Romuald Shmidtelson
  • one
    DATE_ADD (p.post_modified, INTERVAL + p3.meta_value DAY)> = NOW ()) - convert other parameters to p3.meta_value and DATEDIFF in comparison, this will allow you to use g5t_postmeta (meta_key, meta_value) index more efficiently. - Akina
  • @Akina Dear Akina, do you suggest optimizing the query or converting it to wp_query? - Romuald Shmidtelson

0