Warning: DOMDocument::loadHTML(): Tag template invalid in Entity, line: 12 in /home/customer/www/salferrarello.com/public_html/wp-content/plugins/gistpress/includes/class-gistpress.php on line 466
Warning: DOMDocument::loadHTML(): Tag svg invalid in Entity, line: 14 in /home/customer/www/salferrarello.com/public_html/wp-content/plugins/gistpress/includes/class-gistpress.php on line 466
Warning: DOMDocument::loadHTML(): Tag path invalid in Entity, line: 15 in /home/customer/www/salferrarello.com/public_html/wp-content/plugins/gistpress/includes/class-gistpress.php on line 466
Warning: DOMDocument::loadHTML(): Tag template invalid in Entity, line: 27 in /home/customer/www/salferrarello.com/public_html/wp-content/plugins/gistpress/includes/class-gistpress.php on line 466
Warning: DOMDocument::loadHTML(): Tag svg invalid in Entity, line: 29 in /home/customer/www/salferrarello.com/public_html/wp-content/plugins/gistpress/includes/class-gistpress.php on line 466
Warning: DOMDocument::loadHTML(): Tag path invalid in Entity, line: 30 in /home/customer/www/salferrarello.com/public_html/wp-content/plugins/gistpress/includes/class-gistpress.php on line 466
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// add the following code to your functions.php file | |
add_action( 'pre_get_posts', 'fe_pre_get_posts_sticky_only' ); | |
function fe_pre_get_posts_sticky_only( $query ) { | |
if ( | |
$query->is_main_query() | |
&& $query->is_home() | |
) { | |
$query->set( 'post__in', get_option('sticky_posts') ); | |
} | |
} |
Update 2015-09-28 Thanks to Joan in the comments for pointing out the original code posted here was only relevant when using a Genesis Custom Loop. This updated solution applies to the default loop (and is not Genesis specific).
Hi Sal! I’m trying this code but it has no effect on the loop. Tried in functions.php, in my own plugi, even in home.php and front-page.php, but it has no effect.
Am I missing something?
I think you’re right Joan. The current code should only work if you’re using a Custom Genesis Loop. I think using the
pre_get_posts
hook would be the better way to go. I’ll take a look closer and update this post. Thanks for pointing this out.For right now, I think putting the following code into `functions.php` should do the trick
Yeah, now it works great.
So yeah, “genesis_custom_loop_args” only works if you are using “genesis_custom_loop”, which makes sense. 😉
Thanks, Sal! Appreciate!
There might be a use case, why you only want sticky posts. Have you handled a category page where the sticky posts 2 or more are on top and the other post are order by publication date?
I have look around the Interwebs, but couldn’t find this use case.
Hi Birgit,
I don’t do a lot with Sticky posts, which is why I wrote this post to remind myself in the future of how to do this. If you find a solution to your issue, I’d be interested in hearing about it. Best of luck.