wordpresswordpress-jetpack

Jetpack Publicize: Sharing only on Twitter for a category


On my current project I have three post categories (Column, Pickup and News) and use Jetpack Publicize to share any new post on both Facebook and Twitter.

For the "News" category, I'd like to only publicize on Twitter (so somehow deactivating Facebook sharing for this category exclusively).

I have been looking at the Jetpack documentation and adjusted their recommended code:

add_filter( 'wpas_submit_post?', 'news_twitter_submit_post', 10, 4 );
function news_twitter_submit_post( $ret, $post_id, $name, $connection ) {

    // $categories = get_the_terms( $post_id, 'category' );
    $categories = wp_get_post_categories( $post->slug );
    if ( 'facebook' == $name ) {
        if ( is_array( $categories ) )
            $categories = wp_list_pluck( $categories, 'slug' );
        if ( !empty( $categories ) &&  in_array( 'news', $categories ) ){
            $ret = false;
          }
    }
    return $ret; }

Except, the post still is getting published on Facebook.

I have also been looking at the publicize_should_publicize_published_post hook but can't get it to work.

Any way I could achieve this?


Solution

  • So I played a little bit more with Jetpack then decided to switch to another plugin.

    Some notes:

    Still interested in knowing if anyone has a clean solution for that problem, but let's close the question.