Support » Plugin: Jetpack by WordPress.com » How to remove MULTIPLE posts from ‘Top Posts’ widget?

  • Resolved millennial1

    (@millennial1)



    Hi there,

    Quick question. I’m sure it’s trivial, I’m just not that fluent in PHP yet.

    I understand the following code is the suggested way to remove a specific post (via its post_ID) from the ‘Top Posts’ widget.
    Jetpack: remove a post from the Top Posts Widget

    function jeherve_remove_post_top_posts( $posts, $post_ids, $count ) {
        foreach ( $posts as $k => $post ) {
            // Replace 1215 by the ID of the Post you want to remove
            if ( '1215' == $post['post_id'] ) {
                unset( $posts[$k] );
            }
        }
        return $posts;
    }
    add_filter( 'jetpack_widget_get_top_posts', 'jeherve_remove_post_top_posts', 10, 3 );

    However, how would I remove multiple posts? Do I have to use multiple ‘if’s? Or can I somehow use an OR operator or commas? Or something else entirely?

    I haven’t seen anywhere where this is touched on. Anyway, thanks in advance.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support lizkarkoski

    (@lizkarkoski)

    Hi –

    Could you post your site URL here, so I can have a look?

    If you want it to remain private, you can also contact us via this contact form:
    Contact Support

    Hi there,

    MillennialDIYer.com

    Though I don’t see why that would be needed. It’s not so much a question about my site as much as a question regarding the snippet above (or whatever Jetpack officially endorses). Basically I’m just looking for what Jetpack suggests for removing related posts, but just for Top Posts.

    Plugin Support lizkarkoski

    (@lizkarkoski)

    Good morning –

    Thanks for sharing the site with me. We like to make sure Jetpack is installed.

    This request is a bit outside the scope of support that we can provide in the forums. You may require the help of a developer to get this set up, or keep tinkering away on it. We have a developer network at https://jetpack.pro/.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.