search page orderby – prevent ordering by dates
This topic contains 6 replies, has 3 voices, and was last updated by Stiofan O’Connor 7 years, 4 months ago.
We have moved to a support ticketing system and our forums are now closed.
Open Support TicketTagged: orderby search
-
AuthorPosts
-
November 24, 2017 at 5:37 pm #406669
Hi – I see this issue has been flagged in other discussions, but the thread does not seem to provide a solution to prevent modifying core files. Its pretty simple what we need to accomplish – and is described clearly in this thread: https://wpgeodirectory.com/support/topic/sorting-all-organization-page-to-be-alphabetical/
Here is my page at:
It orders the results by date first, but all other pages order by title.
HERE IS the SQL:
SELECT SQL_CALC_FOUND_ROWS wp_posts.*, wp_geodir_gd_place_detail.*
FROM wp_posts JOIN wp_icl_translations icl_t
ON icl_t.element_id = wp_posts.ID
INNER JOIN wp_geodir_gd_place_detail
ON (wp_geodir_gd_place_detail.post_id = wp_posts.ID)
WHERE 1=1
AND ( ( wp_posts.post_title LIKE “” )
OR ( wp_posts.ID IN(
SELECT wp_term_relationships.object_id as post_id
FROM wp_term_taxonomy, wp_terms, wp_term_relationships
WHERE wp_term_taxonomy.term_id = wp_terms.term_id
AND wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id
AND wp_term_taxonomy.taxonomy in ( ‘gd_place_tags’,’gd_placecategory’ ) ) ) )
AND wp_posts.post_type in (‘gd_place’)
AND (wp_posts.post_status = ‘publish’)
AND icl_t.language_code = ‘fr’
AND icl_t.element_type IN(‘post_gd_place’)
AND ( FIND_IN_SET(‘378’, wp_geodir_gd_place_detail.gd_placecategory ) )
ORDER BY wp_geodir_gd_place_detail.is_featured asc, $wpdb->posts.post_date desc, wp_posts.post_title
LIMIT 0, 20Solution
**************
modified wp-content/plugins/geodirectory/geodirectory-functions/listing_filters.php// line 477
//$orderby .= $table . “.is_featured asc, $wpdb->posts.post_date desc, $wpdb->posts.post_title “;
$orderby .= $table . “.is_featured asc, $wpdb->posts.post_title “;MY QUESTION – how can I make that modification using filters or hooks, preventing me to have to modify the actual plugin code?
I have tried with this code – why does this code dont seem to affect the geodirectory loop?
add_action( ‘pre_get_posts’, ‘custom_get_posts’ );
function custom_get_posts( $query ) {
if( $query->is_main_query() ) {
$query->set( ‘orderby’, ‘title’ );
$query->set( ‘order’, ‘DESC’ );// $query->query_vars[‘orderby’] = ‘title’;
// $query->query_vars[‘order’] = ‘ASC’;}
}
Thanks for providing a clear and simple answer to this issue that many people seem to have noticed.
November 24, 2017 at 6:54 pm #406679Hello!
Why aren’t the default sort options working for you? The referenced thread does not make things more clear for me.
https://wpgeodirectory.com/docs/core-place-settings/#sorting
As it says there,
The Sorting Options control how listings are ordered on your Listings (category) pages and in your search results.
On the Search pages, only the default sort order will be used, and only if no keywords were used in the search.Is the issue that you want the results ordered A-Z even if there is a keyword submitted? Or something else?
November 24, 2017 at 7:29 pm #406686please refer to this part of my comment, it explains exactly what I need done, the commented part is the original code, the other part is my modified code.
Basically, we just need to drop the DATE asc ordering from the default sql statement generated by this file, and there seems not to be a mean to do so without modifying this file:
wp-content/plugins/geodirectory/geodirectory-functions/listing_filters.php
// line 477
//$orderby .= $table . “.is_featured asc, $wpdb->posts.post_date desc, $wpdb->posts.post_title “;
$orderby .= $table . “.is_featured asc, $wpdb->posts.post_title “;At this point if you do not understand, im assuming you are not a php developper or are confused, so please get Stephan or someone that knows its way around the code to look at this. As a customer we assume that our questions are going to be looked at and answered by qualified PHP programmers.
Thanks for your honest tentative to help, and lease be assured that I mean no disrespect. 😉
November 24, 2017 at 7:46 pm #406687Hello!
This is a customization that falls outside of our support policy, but we always try to review each request and to provide hooks or filters when we can on a case by case basis. I will flag this for the team, who will be back in the office on Monday.
Thanks for your patience while we look into the matter
Related Links:
https://wpgeodirectory.com/support-policy/November 24, 2017 at 8:02 pm #406689Search is usually ordered by either Location OR relevance, your query is for a empty query, if anything was input it would be sorted by relevance, not a-z.
Stiofan
November 24, 2017 at 9:38 pm #406698and how exactly would “relevance” be calculated? it seems the system has this behavior when we select only a category and leave the keyword field empty as well.
Nevertheless, it seems a pretty simple thing to modify in your code to enable use to use filters to modify the orderby part of query in all cases.
Ive noticed that this line adds the orderby statements AFTER the apply_filter function is called… wouldnt putting the “apply_filter call” AFTER the adding of this code settle the issue?
instead of:$orderby = apply_filters(‘geodir_posts_order_by_sort’, $orderby, $sort_by, $table);
$orderby .= $table . “.is_featured asc, $wpdb->posts.post_date desc, $wpdb->posts.post_title “;
return $orderby;we would have:
$orderby .= $table . “.is_featured asc, $wpdb->posts.post_date desc, $wpdb->posts.post_title “;
return $orderby;
$orderby = apply_filters(‘geodir_posts_order_by_sort’, $orderby, $sort_by, $table);Then we would be able to strip the DATE part of the orderby statements ourselves using filters… does that make sense?
thanks Stiofan
November 25, 2017 at 9:58 am #406746Hi Myrianne,
I will be working on search next week so the query might be changed a bit, i’ll make sure everything can be filtered 🙂
Thanks,
Stiofan
-
AuthorPosts
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket