• Resolved williamrlward

    (@williamrlward)


    Hey,

    I would like for this plugin to only post to discord from a certain category. Not every post.

    How can I do this?

    Thanks
    Will

    The page I need help with: [log in to see the link]

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Nico

    (@nicolamustone)

    Automattic Happiness Engineer

    Hello,
    You can add this code in your functions.php file, at the end of the file (before the sign ?> if you have it):

    
    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( 'Uncategorized', $post );
    }
    

    If you want to check multiple categories, use this:

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

    The post will be published to Discord only if it has the category specified there.

    • This reply was modified 6 years, 10 months ago by Nico. Reason: typo
    Thread Starter williamrlward

    (@williamrlward)

    Thanks! Forgive me im not the best with some coding… what in this code do I need to change to set the correct category?

    In my case the category name I would like streamed is “Contributor”

    Thanks.

    Plugin Author Nico

    (@nicolamustone)

    Automattic Happiness Engineer

    If it’s only one category use the first snippet in my previous reply, and replace the word Uncategorized with Contributor.

    Thread Starter williamrlward

    (@williamrlward)

    IT WORKS! ??

    Thanks!

    Thread Starter williamrlward

    (@williamrlward)

    Actually its not :/ Posting everything.

    https://gyazo.com/e9c5a19b730b5905c6b01ab2d4597f64

    Thread Starter williamrlward

    (@williamrlward)

    With my wordpress theme I can add code into the themes backend. CSS, HTML, Javascript. Will it be better if I put this in there?

    Plugin Author Nico

    (@nicolamustone)

    Automattic Happiness Engineer

    From your screenshot, it shows that it’s the wrong location.
    Add the code at the very end of the file, after the last }. That should make the trick.

    Thread Starter williamrlward

    (@williamrlward)

    whoop! Thanks 100% works now ??

    After adding this code, no posts are pushed to discord. I’ve tried both a singular category and multiple categories in an array. When I remove the code, all posts are pushed.

    I’ve tried this code in both the theme functions.php file as well as using the “Snippets” plugin.

    For a member’s only site, adding the ability to select which categories are pushed to discord from within the dashboard settings would be very helpful.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Only post from a certain catagory’ is closed to new replies.