• Resolved bebibu

    (@bebibu)


    Hi There,

    How to exclude Some Category from Top Post Jetpack? Let say, i want to exclude CAR category to show at TOP POST Jetpack…

    Thank You

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support KokkieH

    (@kokkieh)

    Hi there,

    The Post Posts and Pages widget does not offer any option to exclude posts from a particular category.

    Plugin Support KokkieH

    (@kokkieh)

    Me again ??

    While the widget doesn’t offer a setting for this, you can do it using a code snippet you can add to your site’s functions.php file using a code snippets plugin.

    You can use the jetpack_widget_get_top_posts filter and use it to check the category on posts that are fetched by the widget. Then you can remove the posts if they belong to the specific category.

    You can see details on this filter here:

    https://developer.jetpack.com/hooks/jetpack_widget_get_top_posts/

    Your snippet could be something similar to this example, which removes posts based on their publication date rather than the category.

    https://developer.jetpack.com/2016/01/28/top-posts-pages-widget-remove-all-popular-posts-that-werent-published-within-the-last-month/

    Thread Starter bebibu

    (@bebibu)

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

    This snippet code is actually work.perfect.

    And because i dont understand how to edit/custom the code, so i manually edit the post ID everytime the post for specific category become Trending/Top Post. :)))

    Maybe someone can solve this code

    Thank You

    Plugin Support lizkarkoski

    (@lizkarkoski)

    Hi –

    It’s not clear to me if you still need help. In the reply you said that the “snippet code works perfectly”, and then said, “maybe someone can solve this code.”

    If you’re still needing help please specify which part of @kokkieh’s suggestion is causing you trouble.

    Thanks ??

    Thread Starter bebibu

    (@bebibu)

    Hi,

    that code is only for post and i manually edit the code everytime the post for specific category become Trending/Top Post.

    what i want is snippet code for EXCLUDE CATEGORY but i dont understand how to edit the code.

    thanks

    Plugin Contributor James Huff

    (@macmanx)

    Since that works specifically on posts and doesn’t take category/tag into account, we don’t currently have a way to exclude specific categories or tags.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Exclude Some Category from Top Post Jetpack’ is closed to new replies.