Archive for the ‘WordPress’ Category


Facebook Comments Moderation & WordPress

If you are having trouble with Facebook Comments moderation through WordPress, this may be your solution.

The first thing to always check with Facebook is that you are using their most recent protocols. Facebook is notoriously changing how you must integrate it into your website, to be sure to check this link regularly: https://developers.facebook.com/docs/guides/web/

And the latest code (August 2011) is below. Place this below the opening <body> tag in your HTML document.

<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId:'YOUR_APPLICATION_ID', cookie:true,
status:true, xfbml:true
});
</script>

In order to have comment moderation, you’ll need to do a few things:

1) Set up an App and enable moderator access to whoever needs to have it.
2) Add relevant <meta> property tags to the <head> portion of your website.
3) Match the comment plugin’s href attribute to the current permalink URL.

There are two ways to do the <meta> property tags. You can either enable a specific user to have moderator access or give access to all moderators within the App. Going with the App method is more ideal because it will connect to your App’s dashboard in www.facebook.com/developers/. A direct link to managing comments via the App interface would be https://developers.facebook.com/apps/{YOUR_APPLICATION_ID}/plugins?view=queue. This method’s code is below:

<meta property="fb:app_id" content="{YOUR_APPLICATION_ID}">

You can always read more about the comments plugin by going to https://developers.facebook.com/docs/reference/plugins/comments/ although their documentation is typically confusing and subpar.

One way WordPress can make moderation break is due to the fact that page GUID’s may be different from your permalink URL’s. If you put a $post->GUID into your <fb:comments href=””>, moderation will NOT work. The comments URL and the page URL must be identical. To get the page URL of a post, you can use get_permalink(). By feeding the permalink into your comments plugin and doing the other steps above, you should be in good shape! Just be aware that by changing permalink structure or changing URL’s you will lose all of your comments.

(this solution was discovered via http://forum.developers.facebook.net/viewtopic.php?id=102099)

WordPress – How to Limit Number of Search Results

I had a heck of a time looking for a solution to this very common problem. Fortunately, the solution is quite easy!

WordPress, by default, limits your search results to 10 per page. When doing a normal query, you’d use get_posts(numberposts=99) to determine how many results appear from your query. You use a different parameter, showposts, for search pages.

So how do you modify the query to show what you want? Simply take the current $query_string (generated by WordPress’s header functions) and modify its showposts. Make sure to do this before the loop and you’re all good! All the code you need is below.

[php]query_posts($query_string . ‘&showposts=12′);[/php]


WordPress Pagination 404′s with Custom Post Types

If you’re using custom post types in WordPress and your category pages are throwing 404′s every time you try to paginate, you may be running into a bug with the WordPress core (as of version 3.0.4).

There is a solution — but first make sure that you have:

1) Checked your permalink settings to make sure there is nothing wonky. Try the recommended presets in the permalinks settings page and see if you are still having a problem.

2) View the same category page on the default skin. This will rule out issues that may lie within your specific code.

3) Cried a bit. Just kidding… kinda (I suffered for days before coming to a resolution courtesy of Mark / t31os)

If you’re still getting 404′s… here’s the code that saved my life. Replace your_custom_type with your custom type (surprise). You can put however many custom types as you’d like. Do this in your functions.php.

[php]add_action( 'parse_query','changept' );
function changept() {
	if( is_category() && !is_admin() )
		set_query_var( 'post_type', array( 'post', 'your_custom_type' ) );
	return;
}[/php]



Best of luck! You can view my entire sob story / thread here (and give Mark all of your money if possible).

How to Dynamically Create WordPress Posts

If you’ve ever had a need to dynamically create (or update) WordPress posts, there’s a simple way to do so.  Use wp_insert_post.

// Create post object
  $my_post = array(
     'post_title' => 'My post',
     'post_content' => 'This is my post.',
     'post_status' => 'publish',
     'post_author' => 1,
     'post_category' => array(8,39)
  );

// Insert the post into the database
  wp_insert_post( $my_post );


If you set the ID property of your post array to a number  (i.e. $my_post['ID']  => 15), it will update an existing post rather than adding a new one. Leaving ID blank will create a new post. You cannot force a new post to acquire a specific ID.

For any further details, visit wp_insert_post in the WordPress Codex. For whatever reason, this documentation is not easy to find on Google, so I hope this simple article will make it easier for everyone.