• I want to replace in wordpress query… i want to remove “ORDER BY * 1 ASC” from my current query

    screenshot
    prnt.sc/j9pkmw

    
    SELECT t.*, tt.*
    FROM wp_terms AS t 
    INNER JOIN wp_term_taxonomy AS tt
    ON t.term_id = tt.term_id
    WHERE tt.taxonomy IN ('beds')
    AND t.slug IN ('4')
    ORDER BY * 1 ASC /* From [zzzzzz.wpengine.com/?ct_state=0&ct_price_from&ct_price_to&ct_beds=4&ct_property_type=0&ct_ct_status=0&ct_mls&search-listings=true] in [/nas/content/live/zzzz/wp-content/themes/mycustomtheme/search-listings.php:236] */
    
    ///236 $wp_query = new WP_Query( $search_values ); 
    

    i want add code in functions.php

    • This topic was modified 6 years, 7 months ago by Jan Dembowski. Reason: Fixed formatting

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Ideally, you specify the desired ordering in the $search_values query arguments. When that is not possible, the “orderby” query var can be altered by hooking “pre_get_posst” and setting the query var as desired. You’ll need some sort of conditional to ensure the change is only applied to the specific query and not any others.

    WP always orders by something. If you don’t specify, it’ll order by date DESC. To fully remove the ORDER BY clause to get ordering as found in the table (should be the same as ORDER BY ID), hook the “posts_request” filter and use string functions to remove the ORDER BY clause from the passed SQL query. You will still need to ensure you are only changing the intended query and not any others.

Viewing 1 replies (of 1 total)
  • The topic ‘Replace in wordpress query’ is closed to new replies.