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.
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
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/
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!
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.
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.
That’s interesting. What happens when you use a custom plugin you create, instead of Code Snippets? Do you experience similar issues?
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?
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
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.
Could you copy your custom CSS code and share it here via a tool like http://pastebin.com/ ?
Thanks!
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!
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.
Yes, it looks that way unfortunately!
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