[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 9 posts - 31 through 39 (of 39 total)
  • Author
    Posts
  • #14134

    Tom
    Keymaster

    Yea, 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?

    #14137

    hezuf123
    Participant

    So 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 );
    #14150

    Tom
    Keymaster

    And what about using array_column? You mentioned it output the same as the manual input.

    #14160

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

    • This reply was modified 5 days, 12 hours ago by  hezuf123.
    • This reply was modified 5 days, 12 hours ago by  hezuf123.
    #14177

    Tom
    Keymaster

    Hmm, 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?

    #14185

    hezuf123
    Participant

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

    • This reply was modified 5 days, 1 hour ago by  hezuf123.
    • This reply was modified 5 days, 1 hour ago by  hezuf123.
    #14231

    Tom
    Keymaster

    So 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 );

    #14250

    hezuf123
    Participant

    That works, awesome! Thanks so much for your patience and the outstanding support you provide with all your products.

    • This reply was modified 3 days, 6 hours ago by  hezuf123.
    #14256

    Tom
    Keymaster

    Glad I could help! 🙂

Viewing 9 posts - 31 through 39 (of 39 total)

You must be logged in to reply to this topic.