[Support request] Show posts in current category and specific tag

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Show posts in current category and specific tag

This topic contains 38 replies, has 2 voices, and was last updated by  Tom 3 days ago.

Viewing 15 posts - 16 through 30 (of 39 total)
  • Author
    Posts
  • #13983

    Tom
    Keymaster

    What about this?:

    $args = array(
        'post__in' => array( 305512, 334934, 332645, 334067 ),
        'orderby' => 'post__in',
    );
    
    wpsp_display( 1234, $args );
    #13991

    hezuf123
    Participant

    This 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.

    #14006

    Tom
    Keymaster

    Are 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?

    #14015

    hezuf123
    Participant

    Are 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.

    #14029

    Tom
    Keymaster

    Let’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 );
    #14045

    hezuf123
    Participant

    Now it shows nothing. Should I reverse the code change?

    #14052

    Tom
    Keymaster

    No, 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 );
    #14062

    hezuf123
    Participant

    Sorry, regarding the last snippet I forgot the wpsp_display part. Now that I added it both again just show the latest posts, no changes.

    #14079

    Tom
    Keymaster

    Hmm, 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 );
    #14084

    hezuf123
    Participant

    My 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' );
    #14089

    Tom
    Keymaster

    It’s likely due to how that function is returning the IDs. They need to return in a simple array like the example we created.

    #14107

    hezuf123
    Participant

    Why 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?

    • This reply was modified 1 week, 1 day ago by  hezuf123.
    • This reply was modified 1 week, 1 day ago by  hezuf123.
    • This reply was modified 1 week, 1 day ago by  hezuf123.
    #14119

    Tom
    Keymaster

    It’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

    #14124

    hezuf123
    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?

    #14130

    hezuf123
    Participant

    I also tried it with wp_list_pluck instead of array_column.

Viewing 15 posts - 16 through 30 (of 39 total)

You must be logged in to reply to this topic.