• Resolved problematichild

    (@problematichild)


    Hi,

    We are currently using Relevanssi on our site and have a specific use case that we are looking to implement. Specifically, we would like to include a certain post type in search results on desktop, but exclude that same post type when the search is performed on mobile devices.

    We understand that Relevanssi allows us to include or exclude post types globally, but we haven’t found a way to apply these settings based on the user’s device type (desktop vs. mobile).

    Would you have any recommendations or insights on how best to implement this functionality? We are open to using custom code if necessary and are exploring efficient approaches to modify the search query based on the detected device.

    Any guidance would be appreciated!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Mikko Saari

    (@msaari)

    This one’s simple:

    add_filter( 'relevanssi_modify_wp_query', function( $query ) {
    if ( wp_is_mobile() ) {
    $query->set( 'post_type', array( 'mobile', 'post', 'types', 'here' );
    }
    return $query;
    } );
    Thread Starter problematichild

    (@problematichild)

    Hi @msaari , we tried the code you provided, and it seems to be working. Thank you so much for your help—I really appreciate it.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.