Community Forums › Forums › Archived Forums › Design Tips and Tricks › Genesis (Streamline Pro) Post__In Blogroll Issues
Tagged: blogroll, post__in, pre_get_posts
- This topic has 8 replies, 2 voices, and was last updated 8 years ago by
robindean.
-
AuthorPosts
-
December 23, 2017 at 4:19 pm #214775
robindean
MemberHello, all.
I have an array of 10 post IDs.
Sorted in the same order as the array itself (let's say ... 10, 4, 7, 3, 2, 6, 5, 1, 9, 8), I'd like to use post__in to display ONLY these posts in the blogroll.
The function I've built includes the following if/then:
function customize_blogroll( $query )
{
if ( $query->is_home && $_GET['show'] == 'popular' ) {
$popular_posts = array(10, 4, 7, 3, 2, 6, 5, 1, 9, 8);
$query->set( 'post__in', $popular_posts );
return $query;
{
}
add_action( 'pre_get_posts', 'customize_blogroll' );The problem I'm faced with is a) I don't know how to stop them from being sorted and b) the output doesn't include the primary navigation menu (up top).
I'm fiddling here. Anybody have any notes/advice on why my idea keeps breaking?
https://www.theridingobsession.com/articles/?show=popularShabadoo!
December 25, 2017 at 8:34 am #214799robindean
MemberAlright, well ... onto StudioPress support it is.
Shabadoo!
December 26, 2017 at 10:34 am #214812robindean
Member... aaaaannnd support sent me back here.
Seems I've mistakenly forgotten to use the term "loop" which I'll explore but my issue still remains that I'd like to display a list of very specific post ids in blogroll fashion.
I'm going to try using the is_search page instead. Meanwhile, I'm open to suggestions.
Shabadoo!
December 26, 2017 at 2:22 pm #214817Satwinder Rathore
Participantif you want to sort the posts according to the
arrayTry this$query->set( 'orderby', 'post__in' );
Satwinder Rathore
https://satwinderrathore.wordpress.comDecember 26, 2017 at 2:39 pm #214820robindean
MemberIn doing this, how exactly am I passing the array?
I tried a couple of methods via the WP documentation here: https://codex.wordpress.org/Class_Reference/WP_Query
... but threw an error when using => in the post__in adaption.
Shabadoo!
December 26, 2017 at 4:38 pm #214821robindean
MemberHow do I pass the array into post__in using your suggested method above?
Shabadoo!
December 26, 2017 at 5:10 pm #214822Satwinder Rathore
Participantfunction customize_blogroll( $query ) { if ( $query->is_home && $_GET['show'] == 'popular' ) { $popular_posts = array(10, 4, 7, 3, 2, 6, 5, 1, 9, 8); $query->set( 'post__in', $popular_posts ); $query->set( 'orderby', 'post__in' ); return $query; { } add_action( 'pre_get_posts', 'customize_blogroll' );
Satwinder Rathore
https://satwinderrathore.wordpress.comDecember 26, 2017 at 5:36 pm #214823robindean
MemberI tried this and for some reason it broke the primary navigation menu.
I also attempted to run the same function using an is_search based GET parameter which DID show the primary nav but only returned 7 of the 10 post IDs in the array.
Bizarre.
At this point, it's a fun "puzzle" but I'm prepared to resort to a simple page which lists out the links.
Shabadoo!
December 27, 2017 at 8:33 am #214833robindean
MemberI've since abandoned my original goal and have gone with another solution. Thank you for the assistance and info.
Shabadoo!
-
AuthorPosts
- The topic ‘Genesis (Streamline Pro) Post__In Blogroll Issues’ is closed to new replies.