Title: Mobile Theme Post Order
Last modified: August 31, 2016

---

# Mobile Theme Post Order

 *  Resolved [harry_lime](https://wordpress.org/support/users/harry_lime/)
 * (@harry_lime)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/mobile-theme-post-order/)
 * Hi Theme
 * I’m trying to change the way posts are ordered when on the mobile theme and I
   don’t think I’m getting the hook quite right. I wish to change the “orderby” 
   value to “_expiration_date” as I have it on my desktop homepage.
 * Here’s what I tried:
 *     ```
       // Check if we are on mobile
       function jetpackme_is_mobile() {
   
           // Are Jetpack Mobile functions available?
           if ( ! function_exists( 'jetpack_is_mobile' ) )
               return false;
   
           // Is Mobile theme showing?
           if ( isset( $_COOKIE['akm_mobile'] ) && $_COOKIE['akm_mobile'] == 'false' )
               return false;
   
           return jetpack_is_mobile();
       }
   
       // Modify the main query on the home page for the mobile theme.
       function jetpackme_modify_main_query( $query ) {
           if ( jetpackme_is_mobile() && is_home() ) {
               $query->set('orderby', 'meta_value');
       		$query->set( 'meta_key', '_expiration-date' );
               $query->set( 'order', 'ASC' );
               return;
           }
       }
       add_action( 'pre_get_posts', 'jetpackme_modify_main_query' );
       ```
   
 * Any help would be welcome.
 * Cheers harry
 * [https://wordpress.org/plugins/jetpack/](https://wordpress.org/plugins/jetpack/)

Viewing 15 replies - 1 through 15 (of 40 total)

1 [2](https://wordpress.org/support/topic/mobile-theme-post-order/page/2/?output_format=md)
[3](https://wordpress.org/support/topic/mobile-theme-post-order/page/3/?output_format=md)
[→](https://wordpress.org/support/topic/mobile-theme-post-order/page/2/?output_format=md)

 *  Plugin Author [Jeremy Herve](https://wordpress.org/support/users/jeherve/)
 * (@jeherve)
 * Jetpack Mechanic 🚀
 * [10 years, 2 months ago](https://wordpress.org/support/topic/mobile-theme-post-order/#post-7181238)
 * That code seems correct, except for the `return` call at the end of `jetpackme_modify_main_query`.
   I don’t think it’s necessary.
 * I would also suggest that you check the name of your post meta key. Is it `_expiration_date,
   as you mentioned earlier, or`_expiration-date`, as you used in your code snippet?
 * I hope this helps.
 *  Thread Starter [harry_lime](https://wordpress.org/support/users/harry_lime/)
 * (@harry_lime)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/mobile-theme-post-order/#post-7181239)
 * Hi Jeremy
 * Thanks for the suggestions but it hasn’t helped. The meta key is correct and 
   is already being used for re-ordering the desktop homepage posts and removing
   the _return_ call didn’t break anything but hasn’t had any effect either.
 * I’m at a bit of a loss as the other customizations I’ve made have worked perfectly
   in both the admin and the homepage.
 * Any other ideas?
 * Cheers Marcus
 *  Plugin Author [Jeremy Herve](https://wordpress.org/support/users/jeherve/)
 * (@jeherve)
 * Jetpack Mechanic 🚀
 * [10 years, 2 months ago](https://wordpress.org/support/topic/mobile-theme-post-order/#post-7181249)
 * Could you let me know where you placed that code? Adding it to your theme’s functions.
   php won’t help, since it won’t run when you use another theme, like Jetpack’s
   Mobile Theme.
 * Could you try to add to a functionality plugin like this one, and let me know
   if it helps?
    [https://wordpress.org/plugins/code-snippets/](https://wordpress.org/plugins/code-snippets/)
 *  Thread Starter [harry_lime](https://wordpress.org/support/users/harry_lime/)
 * (@harry_lime)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/mobile-theme-post-order/#post-7181255)
 * Yes, that did indeed work using Code Snippets but this has caused a side-effect
   so that my .css customizations have now become inactive and the look on mobile
   has gone back to the Jetpack default.
 * I will look into why tomorrow unless you already know about the issue.
 * Greatly appreciate the help anyway!
 *  Plugin Author [Jeremy Herve](https://wordpress.org/support/users/jeherve/)
 * (@jeherve)
 * Jetpack Mechanic 🚀
 * [10 years, 2 months ago](https://wordpress.org/support/topic/mobile-theme-post-order/#post-7181256)
 * I can’t think about anything in the code snippet above that would do that. Where
   did you store those CSS changes before?
 * It might be worth storing them in a separate plugin as well.
 *  Thread Starter [harry_lime](https://wordpress.org/support/users/harry_lime/)
 * (@harry_lime)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/mobile-theme-post-order/#post-7181257)
 * Yes agree, it’s a strange one.
 * I have the mobile CSS changes in Jetpack’s Edit CSS plugin away from my other
   CSS coding but for some reason, when I activate the code through Code Snippets,
   the customizations aren’t applied and as soon as I de-activate the code, their
   back working.
 *  Plugin Author [Jeremy Herve](https://wordpress.org/support/users/jeherve/)
 * (@jeherve)
 * Jetpack Mechanic 🚀
 * [10 years, 2 months ago](https://wordpress.org/support/topic/mobile-theme-post-order/#post-7181258)
 * That’s interesting. What happens when you use a custom plugin you create, instead
   of Code Snippets? Do you experience similar issues?
 *  Thread Starter [harry_lime](https://wordpress.org/support/users/harry_lime/)
 * (@harry_lime)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/mobile-theme-post-order/#post-7181259)
 * To be honest, it’s the first time I’ve inserted this kind of script in this way(
   normally I write into the actual framework of the site). Do you have a suggestion
   of another good one to try similar to Code Snippets?
 *  Plugin Author [Jeremy Herve](https://wordpress.org/support/users/jeherve/)
 * (@jeherve)
 * Jetpack Mechanic 🚀
 * [10 years, 2 months ago](https://wordpress.org/support/topic/mobile-theme-post-order/#post-7181260)
 * You could try to go to Plugins > Add New > Upload, and upload and install this
   little plugin instead of using the Code Snippets plugin:
    [http://i.wpne.ws/fSgh](http://i.wpne.ws/fSgh)
 *  Thread Starter [harry_lime](https://wordpress.org/support/users/harry_lime/)
 * (@harry_lime)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/mobile-theme-post-order/#post-7181264)
 * Ok, I uploaded the plugin and disabled Code Snippets.
 * The actual full posts and inner pages are showing the customized version as it
   should be but the problem remains with the homepage where the posts are re-ordered
   correctly.
 * So it does seem to be the code itself which is affecting the customization.
 *  Plugin Author [Jeremy Herve](https://wordpress.org/support/users/jeherve/)
 * (@jeherve)
 * Jetpack Mechanic 🚀
 * [10 years, 2 months ago](https://wordpress.org/support/topic/mobile-theme-post-order/#post-7181285)
 * Could you copy your custom CSS code and share it here via a tool like [http://pastebin.com/](http://pastebin.com/)?
 * Thanks!
 *  Thread Starter [harry_lime](https://wordpress.org/support/users/harry_lime/)
 * (@harry_lime)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/mobile-theme-post-order/#post-7181289)
 * Actually, I’ve managed to isolate the problem although it hasn’t helped me with
   a solution yet.
 * So the original code which works but effects the customization is (I tried with
   different custom Meta Keys with the same effect):
 *     ```
       $query->set('orderby', 'meta_value');
       		$query->set( 'meta_key', '_expiration-date' );
               $query->set( 'order', 'ASC' );
       ```
   
 * If I try a code without a custom Meta Key, then it works as ordered and everything
   looks fine. For eks:
 *     ```
       $query->set('orderby', 'date');
               $query->set( 'order', 'ASC' );
       ```
   
 * Of course, the problem is that I need to use a custom Meta Key to order the posts
   correctly but it’s a step forward I guess!
 *  Plugin Author [Jeremy Herve](https://wordpress.org/support/users/jeherve/)
 * (@jeherve)
 * Jetpack Mechanic 🚀
 * [10 years, 2 months ago](https://wordpress.org/support/topic/mobile-theme-post-order/#post-7181291)
 * I wonder if the custom ordering also changes the classes added to the post content,
   or the page body. That could explain why CSS customizations disappear, if the
   classes you use to make those changes disappear as well.
 *  Thread Starter [harry_lime](https://wordpress.org/support/users/harry_lime/)
 * (@harry_lime)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/mobile-theme-post-order/#post-7181292)
 * Yes, it looks that way unfortunately!
 *  Plugin Author [Jeremy Herve](https://wordpress.org/support/users/jeherve/)
 * (@jeherve)
 * Jetpack Mechanic 🚀
 * [10 years, 2 months ago](https://wordpress.org/support/topic/mobile-theme-post-order/#post-7181294)
 * Would you be able to use different classes to make you changes?
 * If so, you could use the `body_class` filter to add the classes you need:
    [https://codex.wordpress.org/Plugin_API/Filter_Reference/body_class](https://codex.wordpress.org/Plugin_API/Filter_Reference/body_class)

Viewing 15 replies - 1 through 15 (of 40 total)

1 [2](https://wordpress.org/support/topic/mobile-theme-post-order/page/2/?output_format=md)
[3](https://wordpress.org/support/topic/mobile-theme-post-order/page/3/?output_format=md)
[→](https://wordpress.org/support/topic/mobile-theme-post-order/page/2/?output_format=md)

The topic ‘Mobile Theme Post Order’ is closed to new replies.

 * ![](https://ps.w.org/jetpack/assets/icon.svg?rev=2819237)
 * [Jetpack - WP Security, Backup, Speed, & Growth](https://wordpress.org/plugins/jetpack/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/jetpack/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/jetpack/)
 * [Active Topics](https://wordpress.org/support/plugin/jetpack/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/jetpack/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/jetpack/reviews/)

## Tags

 * [mobile](https://wordpress.org/support/topic-tag/mobile/)
 * [order](https://wordpress.org/support/topic-tag/order/)
 * [posts](https://wordpress.org/support/topic-tag/posts/)

 * 40 replies
 * 2 participants
 * Last reply from: [harry_lime](https://wordpress.org/support/users/harry_lime/)
 * Last activity: [10 years, 2 months ago](https://wordpress.org/support/topic/mobile-theme-post-order/page/3/#post-7181361)
 * Status: resolved