WordPress Discord Post: Send only specific categories

If you own a Discord server and a WordPress website, you should probably check out my plugin WordPress Discord Post.

This plugin is an integration between your WordPress website and your Discord server, sending to the second one messages when a new post is published, or a contact form is submitted, or even when a new WooCommerce order is received!

Many people though asked me how to send to Discord only posts from specific categories. Here you can find a snippet for this.

Open your functions.php file in wp-content/themes/your-child-theme-name/ and add this code at the end of the  file:

add_filter( 'wp_discord_post_is_new_post', 'wp_discord_post_limit_by_category' );
function wp_discord_post_limit_by_category( $post ) {
return has_category( 'Your Category Name', $post );
}
view raw functions.php hosted with ❤ by GitHub

This snippet will send only posts from a single category to Discord. In this example the category name is Your Category Name but of course you should change it to something real.

Sending posts to Discord from multiple categories

What if yo want to send posts from multiple categories instead? The code is similar, but you must use an array of categories instead of a simple string:

add_filter( 'wp_discord_post_is_new_post', 'wp_discord_post_limit_by_category' );
function wp_discord_post_limit_by_category( $post ) {
return has_category( array( 'Category 1', 'Category 2' ), $post );
}
view raw functions.php hosted with ❤ by GitHub

Replace Category  1 and Category 2 with the names of the categories that you want to send to Discord. You can also add more than two categories in the list.


More Posts That You Might Like…


One response to “WordPress Discord Post: Send only specific categories”

  1. hi Nicola,
    Thank you.This is great tutorial about how to send to Discord only posts from specific categories – WordPress Discord Post.
    here you can read more about WordPress https://www.redflixmedia.com/

Leave a Reply

Categories

Newsletter

Receive new articles from this blog directly in your inbox!

No spam guaranteed!

Blog at WordPress.com.

%d bloggers like this: