Hello, Niddy,
1) Please try using the following code:
add_action( 'pre_get_posts', function( $q ) {
if ( is_admin() || ! $q->is_main_query() ) return;
if ( $q->is_search() ) {
$pt = $q->get( 'post_type' );
if ( empty( $pt ) || 'product' === $pt ) {
$q->set( 'orderby', 'title' );
$q->set( 'order', 'ASC' );
}
}
}, 20 );
2) Note that the mentioned JavaScript will not work as expected, since it only changes the current value in the select element without actually triggering the selection. If you would like the new value to take effect, you need to use a trigger to initiate the select action after updating its value.
Best regards,
8Theme Team















