问题
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?
回答1:
So I played a little bit more with Jetpack then decided to switch to another plugin.
Some notes:
I played a little bit with publicize_should_publicize_published_post and it's basically a big ON/OFF switch for the whole Publicize plugin. Can't get it to turn off only one channel (Facebook)
No matter how I expressed the if-else conditions, Facebook posting still went through, eventhough I did check the output of the function was correct.
Still interested in knowing if anyone has a clean solution for that problem, but let's close the question.
来源:https://stackoverflow.com/questions/48435992/jetpack-publicize-sharing-only-on-twitter-for-a-category