Home › Forums › Pro Support › Show posts in current category and specific tag
- This topic has 38 replies, 2 voices, and was last updated 2 years, 10 months ago by
Tom.
-
AuthorPosts
-
March 21, 2020 at 5:24 pm #14134
Tom
KeymasterYea, that looks correct. Just to confirm, it works fine with the same numbers manually entered?
That doesn’t make any sense, something else must be going on. You tried without
implode()
, yea?March 22, 2020 at 7:40 am #14137hezuf123
ParticipantSo this is works:
add_filter( 'wp_show_posts_shortcode_args', function( $args, $settings ) { if ( 1234 === $settings['list_id'] ) { $args['post__in'] = array( 305512, 334934, 332645, 334067 ); } return $args; }, 10, 2 ); wpsp_display( 1234, $args );
But this doesn’t work:
$scores = get_crp_posts_id(); $rel_posts = wp_list_pluck( (array) $scores, 'ID' ); add_filter( 'wp_show_posts_shortcode_args', function( $args, $settings ) { if ( 1234 === $settings['list_id'] ) { $args['post__in'] = $rel_posts; } return $args; }, 10, 2 ); wpsp_display( 1234, $args );
And this doesn’t work either:
$scores = get_crp_posts_id(); $rel_posts = wp_list_pluck( (array) $scores, 'ID' ); $rel_posts_sep = implode(', ', $rel_posts); add_filter( 'wp_show_posts_shortcode_args', function( $args, $settings ) { if ( 1234 === $settings['list_id'] ) { $args['post__in'] = $rel_posts_sep; } return $args; }, 10, 2 ); wpsp_display( 1234, $args );
March 22, 2020 at 5:24 pm #14150Tom
KeymasterAnd what about using
array_column
? You mentioned it output the same as the manual input.March 23, 2020 at 4:29 am #14160hezuf123
Participant$scores = get_crp_posts_id(); $rel_posts = array_column( (array) $scores, 'ID' ); add_filter( 'wp_show_posts_shortcode_args', function( $args, $settings ) { if ( 1234 === $settings['list_id'] ) { $args['post__in'] = $rel_posts; } return $args; }, 10, 2 ); wpsp_display( 1234, $args );
This doesn’t work either unfortunately.
March 23, 2020 at 3:42 pm #14177Tom
KeymasterHmm, I’m not sure what’s going on in that case.
You could try debugging the args:
$scores = get_crp_posts_id(); $rel_posts = array_column( (array) $scores, 'ID' ); add_filter( 'wp_show_posts_shortcode_args', function( $args, $settings ) { if ( 1234 === $settings['list_id'] ) { $args['post__in'] = $rel_posts; } // This should output your IDS for the post__in value. var_dump($args); return $args; }, 10, 2 ); wpsp_display( 1234, $args );
Are they visible in your args?
March 23, 2020 at 4:11 pm #14185hezuf123
ParticipantSo this:
$scores = get_crp_posts_id(); $rel_posts = array_column( (array) $scores, 'ID' ); add_filter( 'wp_show_posts_shortcode_args', function( $args, $settings ) { if ( 340019 === $settings['list_id'] ) { $args['post__in'] = $rel_posts; } // This should output your IDS for the post__in value. var_dump($args); return $args; }, 10, 2 ); wpsp_display( 340019, $args );
Gives out this:
array(7) { [“order”]=> string(4) “desc” [“orderby”]=> string(4) “date” [“post_type”]=> string(4) “post” [“posts_per_page”]=> int(3) [“post_status”]=> array(1) { [0]=> string(7) “publish” } [“post__not_in”]=> array(1) { [0]=> int(340029) } [“post__in”]=> NULL }
And
$scores = get_crp_posts_id(); $rel_posts = array_column( (array) $scores, 'ID' ); var_dump($rel_posts)
Gives out:
array(4) { [0]=> string(6) “305637” [1]=> string(6) “337823” [2]=> string(6) “340106” [3]=> string(6) “339780” }
Which are the 4 IDs I want to display.
I am using GP elements to insert the snippet on the page by the way.
March 24, 2020 at 7:48 pm #14231Tom
KeymasterSo that’s showing that the condition is wrong.
Try adding this using one of these methods: https://docs.wpshowposts.com/article/adding-php/
add_filter( 'wp_show_posts_shortcode_args', function( $args, $settings ) { $scores = get_crp_posts_id(); $rel_posts = array_column( (array) $scores, 'ID' ); if ( '340019' == $settings['list_id'] ) { $args['post__in'] = $rel_posts; } // This should output your IDS for the post__in value. var_dump($args); return $args; }, 10, 2 );
Then this in your Element:
wpsp_display( 340019, $args );
March 25, 2020 at 9:25 am #14250hezuf123
ParticipantThat works, awesome! Thanks so much for your patience and the outstanding support you provide with all your products.
March 25, 2020 at 5:26 pm #14256Tom
KeymasterGlad I could help! 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.