Skip Navigation

[Resolved] Search all posts and ignore ordering

This thread is resolved. Here is a description of the problem and solution.

Problem:
Search all posts and ignore ordering on post type archive

Solution:
To override the ordering for post type archive - you should use the WordPress standard function pre_get_posts().

You can find proposed solution, in this case, with the following reply:
=> https://toolset.com/forums/topic/search-all-posts-and-ignore-ordering/#post-1074833

Relevant Documentation:
https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts

This support ticket is created 6 years, 5 months ago. 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.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 1 reply, has 2 voices.

Last updated by Minesh 6 years, 5 months ago.

Assisted by: Minesh.

Author
Posts
#1074408

Hello, I have a default ordering enabled which orders all post by a custom field on the product archive page.

The custom field order is the default order however when I search I want to search all posts according to their post date.

Do you know what I mean?

The search should include &wpv_sort_orderby=post_date and ignore the default custom field ordering.

Do you know how I can do this?

Regards,
Nick

#1074833

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - to override the ordering for post type archive - you should use the WordPress standard function pre_get_posts().

For example - please try to add following code to your current theme's functions.php file:

function func_orderby_postdate($query) { 
    if ($query->is_post_type_archive('product ') && $query->is_main_query()) {
    $query->set('order', 'ASC');
     $query->set('orderby', 'post_date');
    }
}
add_action('pre_get_posts', 'func_orderby_postdate');