• Resolved Yake

    (@yake)


    Hello!

    I have a function that makes the order of my posts appear random.

    It looks like this

    session_start();
    
    add_filter( 'posts_orderby', 'randomise_with_pagination' );
    function randomise_with_pagination( $orderby ) {

    I would like to disable this function on the mobile site. But im not sure how to do this, do you guys have any tips?

    Regards
    Jakob

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    Put if ( ! wp_is_mobile() ) in front of add_filter() ??

    Thread Starter Yake

    (@yake)

    Thank you! Works like a charm.

    If you dont mind me asking, why does this work? Trying to learn more.

    /Yake

    Moderator bcworkz

    (@bcworkz)

    The resulting code line is saying in plain English “If the requesting device is NOT a mobile, add in the randomise filter.”

    The ‘!’ is the PHP NOT operator, reversing any boolean logic. wp_is_mobile() simply looks in the user agent field sent by a device’s browser for certain key words like “Android”, “BlackBerry”, etc. So your randomise function is only added to the orderby filter when no such keywords are found.

    The orderby filter inserts anything returned by a callback function after the “ORDER BY” directive of the SQL query being processed.

    Thread Starter Yake

    (@yake)

    Aha, i see. Thank you for taking the time to explain, much appriciated!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Disable random post function on mobilesite’ is closed to new replies.