Archived topic
How to list explicit posts on explicit pages ?
33 replies · Started by Tim on September 29, 2021
Hello Elvin
Thank you for your perseverance.
So this is the part I was referring to earlier where I'm not so confident about employing the beta version, and not certain if the ACF Return Format is suitable for the WPSP beta version, which is something you highlighted as a possible issue.
The Element Hook: "Client & Partner Profile Element with WPSP" (ID:4002)
The WPSP List: "Client Featured Posts" (ID:4004)
Snippet: "Display Client & Partner Profile Fields on Client & Partner Child Pages" (ID:12)
The snippet is required for displaying the Element Hook on child pages of a list of parent pages (would be nice if Hooks could do this without the snippet)
I installed WPSP 1.2.0-alpha.3 and attempted the proposed code, but the list was not displayed, so reverted.
Ah I see now.
Here's what we can do:
1.) Remove this code on your hook element:
<?php
$featured_posts = get_field('featured_posts',get_queried_object_id());
$settings = array(
'post__in' => $featured_posts,
'orderby' => 'post__in'
);
wpsp_display( 4004 , $settings );
?>
2.) replace the removed code with this shortcode [wp_show_posts id="4004"] and make sure "Execute Shortcode" is ticked on the hook element.
3.) Go to WP Show Posts and edit WPSP list ID 4004. Make sure the Post tab's query is only set to "posts" and keep the taxonomy query empty. (Keep the dropdown blank. no tags or category)
4.) Go to your ACF field for featured image. Make sure it returns "Post ID" and not "Post Object".
5.) On your PHP snippets, add this code:
add_filter( "wp_show_posts_shortcode_args", function ($args, $settings) {
$featured_posts = get_field('featured_posts',get_queried_object_id());
if (4004 === (int) $settings["list_id"]) {
$args['post__in'] = $featured_posts;
}
return $args;
},15,2);
This should modify the post listing. :)
Hello Elvin
Thank you for taking the time to investigate my case scenario.
Yes, now the explicitly selected posts are being displayed on explicit pages with the WPSP list, date order and styling.
Fantastic.
Would you mind explaining the configuration a little, ie why is a shortcode employed via the Hook and in this case ?
Importantly, is there anything I should be aware of regarding the alpha/beta version of the WPSP plugin, and when might a release version be available ?
Thanks
Would you mind explaining the configuration a little, ie why is a shortcode employed via the Hook and in this case ?
The code on #1 was just wrong because I assumed there was a post__in array value inside settings here - https://github.com/tomusborne/wp-show-posts/blob/1ff2257b0e8f5b899dd5f682979733cc36bb48ea/wp-show-posts.php#L96-L146 - which was wrong.
That's why it didn't work. That's my bad. :|
I had to change the code to use a shortcode because wpsp_display function completely bypasses the shortcode params so the wp_show_posts_shortcode_args works.
But going back, I think, to make the wpsp_display work, we need something like this instead.
<?php
$featured_posts = get_field('featured_posts',get_queried_object_id());
$iteration = 1;
$length = count($featured_posts);
foreach ($featured_posts as $post_id) {
if ($iteration === $length) {
$post_ids .= $post_id;
} else {
$post_ids .= $post_id.',';
$iteration++;
}
}
$settings = array(
'post_id' => $post_ids,
);
if ( function_exists( 'wpsp_display' ) ) wpsp_display( 4004, $settings );
?>
But this is just me winging it based on I skimmed WPSP's code just now and did a quick test (which worked). I assume it should work on your end as well if you do this.
Importantly, is there anything I should be aware of regarding the alpha/beta version of the WPSP plugin, and when might a release version be available ?
Tom has yet to announce any ETA. The devs are quite swamped at the moment because GP + GPP + GB has a pending new release coming soon. (likely next week)