A while back I began using Otto‘s Simple Facebook Connect plugin, and I love it!  It just works.  I’d tried so many different integration plugins, and none worked perfectly.  After working through a few hiccups, mostly caused by other plugins, I have it running smoothly.  One thing I love about the plugin is the auto-posting feature.  I make a post here on my blog, and it appears on Facebook.  Nice little picture, little excerpt, and a link.  But one thing I had to figure out is how to block a specific Custom Post Type (CPT) from auto-publishing. 

 

See, I have several Custom Post Types, and I want most of them to auto-publish. Posts like products, or members are important. We want everyone to see what new products we are featuring, or any new members that jump into The Voodoo Empire. But we also have our hockey posts. That’s a CPT that is auto posted from various RSS feeds. It can have more than ten posts a day, and there is no reason for me to be spewing that all over the internet. So here’s my trick, it will work for various things besides just CPTs, so adapt as you see fit! 

First off, find this block of code in the SFC-publish module.  I won’t bother with line numbers, as that has changed from version to version with various updates.  It’s towards the bottom of the code.

function sfc_publish_automatic($id, $post) {
	// check to make sure post is published
	if ($post->post_status !== 'publish') return;

Now just add in a line like this.  This is for my CPT which is called col_avs.  You can swap out the name of the CPT obviously, or change it from a CPT entirely to something else.

	if ($post->post_type == 'col_avs') return;

You should end up with a block like this. 

function sfc_publish_automatic($id, $post) {
	// check to make sure post is published
	if ($post->post_status !== 'publish') return;
	if ($post->post_type == 'col_avs') return;

SO, the original line in the code said that if the post does not equal published (!==) then don’t send it to Facebook.  The line I’m adding in here says if the post does equal (==) col_avs CPT then don’t send it to Facebook.  Knowing what we have here can help you adapt it to your situation.  And Presto, we’ve adapted the code to our needs. 

Remember to take notes, jot down the change you made.  Every time the plugin is upgraded you’ll have to edit this.  Of course, this is my quick hack way of doing this.  I’m sure there is a better way, but this is quick and painless.  If you know a better way, send it my way!

css.php
%d bloggers like this: