Home › Forums › Pro Support › Show posts in current category and specific tag
- This topic has 38 replies, 2 voices, and was last updated 3 years, 6 months ago by
Tom.
-
AuthorPosts
-
March 14, 2020 at 5:37 pm #13983
Tom
KeymasterWhat about this?:
$args = array( 'post__in' => array( 305512, 334934, 332645, 334067 ), 'orderby' => 'post__in', ); wpsp_display( 1234, $args );
March 14, 2020 at 6:34 pm #13991hezuf123
ParticipantThis shows a different selection of posts, definitely not the ones of those 4 ID’s. I can’t really say what the filter is now, but it’s not the latest posts anymore.
March 15, 2020 at 8:12 pm #14006Tom
KeymasterAre we sure nothing else is conflicting with the query? Another list on the page? A function using
pre_get_posts
?What are the IDs of the posts that are displaying?
March 16, 2020 at 4:56 am #14015hezuf123
ParticipantAre we sure nothing else is conflicting with the query? Another list on the page? A function using pre_get_posts?
Not that I know of…
What are the IDs of the posts that are displaying?
They are apparently still ordered by date but start from the back now, showing the earliest posts.
March 16, 2020 at 5:25 pm #14029Tom
KeymasterLet’s try something else.
First, you’ll need to make this change to the core code: https://github.com/tomusborne/wp-show-posts/commit/286caf1164db8b6b6f38b85d3a011b519a27f4de
Then, do this:
add_filter( 'wp_show_posts_shortcode_args', function( $args, $settings ) { if ( 123 === $settings['list_id'] ) { $args['post__in'] = array( 305512, 334934, 332645, 334067 ); $args['orderby'] = 'post__in'; } return $args; }, 10, 2 );
March 17, 2020 at 6:33 am #14045hezuf123
ParticipantNow it shows nothing. Should I reverse the code change?
March 17, 2020 at 5:17 pm #14052Tom
KeymasterNo, let’s run with it a bit.
How about this?:
add_filter( 'wp_show_posts_shortcode_args', function( $args, $settings ) { if ( 123 === $settings['list_id'] ) { $args['post__in'] = array( 305512, 334934, 332645, 334067 ); } return $args; }, 10, 2 );
March 18, 2020 at 5:23 am #14062hezuf123
ParticipantSorry, regarding the last snippet I forgot the wpsp_display part. Now that I added it both again just show the latest posts, no changes.
March 18, 2020 at 5:19 pm #14079Tom
KeymasterHmm, doesn’t sound right.
What’s the debug output if you do this?:
add_filter( 'wp_show_posts_shortcode_args', function( $args, $settings ) { if ( 123 === $settings['list_id'] ) { $args['post__in'] = array( 305512, 334934, 332645, 334067 ); } var_dump($args); return $args; }, 10, 2 );
March 19, 2020 at 4:58 am #14084hezuf123
ParticipantMy bad, this snippet actually works, I just didn’t realize I had to replace “123”.
add_filter( 'wp_show_posts_shortcode_args', function( $args, $settings ) { if ( 123 === $settings['list_id'] ) { $args['post__in'] = array( 305512, 334934, 332645, 334067 ); } return $args; }, 10, 2 );
However, what I still don’t get to work is getting the output of this to display:
$scores = get_crp_posts_id(); $rel_posts = array_column( (array) $scores, 'ID' );
March 19, 2020 at 5:34 pm #14089Tom
KeymasterIt’s likely due to how that function is returning the IDs. They need to return in a simple array like the example we created.
March 20, 2020 at 4:53 am #14107hezuf123
ParticipantWhy is this not working then, even tho it gives out the format you said is needed:
$scores = get_crp_posts_id(); $rel_posts = array_column( (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 );
All it does is showing the latest posts again.
Also
$scores = get_crp_posts_id(); $rel_posts = array_column( (array) $scores, 'ID' ); print_r( $rel_posts )
Gives out the same format as
$rel_posts = array( 305512, 334934, 332645, 334067 ); print_r( $rel_posts )
So why would I need to change anything on the format? All I need is to display an array of post IDs with WPSP now or am I missing something?
March 20, 2020 at 8:26 pm #14119Tom
KeymasterIt’s likely not being output in the exact same format. What’s the result of your print_r?
If the output was the same, it would work the same as when we manually input the numbers.
If the output is multidimensional, has keys and values etc.. it won’t work. It just needs to be a simple array of values: https://developer.wordpress.org/reference/classes/wp_query/#post-page-parameters
March 21, 2020 at 5:42 am #14124hezuf123
Participant$scores = get_crp_posts_id(); $rel_posts = array_column( (array) $scores, 'ID' ); print_r( $rel_posts )
And
$rel_posts = array( 305512, 334934, 332645, 334067 ); print_r( $rel_posts )
Are both giving out the same:
Array ( [0] => 305512 [1] => 334934 [2] => 332645 [3] => 334067 )
Isn’t that the exact same format? What do I need to change?
March 21, 2020 at 8:22 am #14130hezuf123
ParticipantI also tried it with wp_list_pluck instead of array_column.
-
AuthorPosts
- You must be logged in to reply to this topic.