TaylorLovett

Pull Feed Content into Your WordPress Site

April 8, 2014 by Taylor Lovett

For the past year or so I’ve been using Automattic’s Syndication plugin to pull feed content into my WordPress plugin. Feeds that I designate are pulled in as posts using WordPress Cron. I decided while the plugin worked well for the most part, it wasn’t quite meeting my needs. This prompted me to build a new plugin called Feed Pull.

Here are some differences between the two plugins:

  • Feed Pull is a plugin for pulling content out of XML feeds. Syndication has feed pulling as well as content pushing features.
  • Feed Pull has a much friendlier feed management screen. Both Syndication and Feed Pull use the WordPress post edit, screen, however Feed Pull offers a much cleaner experience from the way options are presented to the instructions provided. At the moment Feed Pull does not have all the features of Syndication such as taxonomy and constant field mapping. However, Feed Pull probably has everything you need and is very extensible.
  • Feed Pull has far superior error logging to Syndication.
  • Feed Pull allows you to schedule content pulling in the future.
  • Feed Pull allows you to do manual pulls using AJAX rather than a sometimes frustrating one-time cron job.

Feed Pull contributions are always welcome on Github.

Introducing Post Customizer

December 17, 2013 by Taylor Lovett

10up just released a new plugin called the Post Customizer. I, along with John James Jacoby, John Bloch, Drew Jaynes, and Carl Danley led the charge on the plugin. The idea of the plugin is to mimic the theme customizer for posts. The plugin adds functionality that displays an overlay when you click “Preview” within the post editor. The overlay has a sidebar allowing you to edit the excerpt and featured post. In the middle of the overlay is a frame that shows the front of the website. Within that frame you can edit the post title and content. This enables you to make “live” changes and to see how they look as you make them. There are other plugins that offer similar behavior. However, Post Customizer closely follows the Theme Customizer and thus WordPress standards.

We want to make this plugin super extensible, and we need all the help we can get. We would appreciate contributions! Fork the plugin on Github.

Why Are Taxonomy Lookups Faster than Post Meta Lookups?

May 14, 2013 by Taylor Lovett

So I’ve read all over the place that looking for posts based on a taxonomy is much quicker than looking up posts based on post meta. But why? I’ve yet to read any sort of technical explanation that satisfies my curiosity. I decided to do some research.

I wrote some example code and used the debug plugin to examine the resulting SQL queries. Here is a post meta query:

$args = array(
  'meta_query' =>
    array(
      array(
        'key' => 'test_key',
        'value' => '1'
      )
    )
);
$query = new WP_Query( $args2 );

Here is the resulting SQL:

SELECT SQL_CALC_FOUND_ROWS trunk_posts.ID
FROM trunk_posts INNER JOIN trunk_postmeta ON (trunk_posts.ID = trunk_postmeta.post_id)
WHERE 1=1 AND
trunk_posts.post_type = 'post' AND
(trunk_posts.post_status = 'publish' OR trunk_posts.post_status = 'private') AND
( (trunk_postmeta.meta_key = 'test_key' AND
CAST(trunk_postmeta.meta_value AS CHAR) = '1') )
GROUP BY trunk_posts.ID
ORDER BY trunk_posts.post_date DESC
LIMIT 0, 10

As you can see the posts table is being joined with the post meta table. A join very basically creates a temporary table where every row in the posts table is matched with every row in the post meta table. The ON clause then narrows down that temporary table keeping only rows of posts that have been matched with post meta that apply to that post. Here is a database model of the post and post meta tables:

postmeta_table

This joining of posts with corresponding post meta rows is done by comparing values across two indexed columns (trunk_posts.ID and trunk_postmeta.post_id) as shown in the diagram. Creating an index on a column in MySQL makes lookups on the column much quicker. Simply put, MySQL stores a B-Tree of the values in that column. A B-Tree is a data structure that allows search in O(log n) time (vs. O(n) time on an unindexed column). The disadvantage in indexing a column with a B-Tree type data structure is that inserting and deleting becomes much slower because parts of the tree must be rebuilt; this is generally a worthwhile sacrifice.

Next, the WHERE statement narrows down posts by meta key only keeping rows that have meta_key=’test_key’. Again, as shown in the diagram, trunk_postmeta.meta_key is an indexed column. So again we can do this in O(log n) time. Awesome, so where is the slow down? Well, the last thing we have to do is narrow the posts so we only have ones where meta_value=’1′. There is no index on the meta_value column. We have refined our posts as follows:

  1. posts matching with every post meta row
  2. posts matching with only post meta that applies to that post
  3. posts matching with post meta for that post with key ‘test_key’
  4. posts matching with post meta for that post with key ‘test_key’ and value ’1′.

On the final refinement, if there are multiple post meta rows with the same key associated, then we will have to search through multiple values until we find a matching value. This search will happen in O(n) which is slow.

Now let’s look at how a taxonomy query works. Here is my taxonomy query code:

$args = array(
  'tax_query' => array(
    array(
      'taxonomy' => 'category',
      'field' => 'id',
      'terms' => array( 2 ),
    )
  )
);
$query = new WP_Query( $args );

Here is the resulting SQL:

SELECT SQL_CALC_FOUND_ROWS trunk_posts.ID
FROM trunk_posts INNER JOIN trunk_term_relationships ON (trunk_posts.ID = trunk_term_relationships.object_id)
WHERE 1=1 AND
( trunk_term_relationships.term_taxonomy_id IN (2) ) AND
trunk_posts.post_type = 'post' AND
(trunk_posts.post_status = 'publish' OR trunk_posts.post_status = 'private')
GROUP BY trunk_posts.ID
ORDER BY trunk_posts.post_date DESC LIMIT 0, 10

As you can see the trunk_posts table is joined with the trunk_term_relationships table. The two tables are joined into a temporary table which is refined by the ON portion of the join statement matching each term row with it’s corresponding posts.

taxonomy_table

As shown in the diagram there is an index on trunk_posts.ID and trunk_term_relationships.object_id, so this first refinement can be done in O(log n) time. Next the WHERE clause refines the temporary table so that only posts matched with the term id 2 are left. There is an index on the term_taxonomy_id column so this can be done in O(log n) time. Obviously, there is more to the query then just this but we don’t care about anything else for now.

Summary:

Post meta queries will experience a major slowdown if the key(s) being searched are associated with a large amount of posts. Another big reason to avoid post meta queries is because the post meta table is typically much larger than the taxonomy_term_relationships table. Therefore doing a join with posts and postmeta is a much more expensive operation than joining posts and taxonomy_term_relationships. This analysis doesn’t take into account caching and is drastically simplified. If you have any questions or corrections, please leave a comment.

Safe Redirect Manager

January 8, 2013 by Taylor Lovett

Hey Everyone!

I wanted to let everyone know about a new WordPress plugin called Safe Redirect Manager. I am one of the main developers of this plugin, and it has just been released on WordPress.org along with WordPress.com VIP (which is quite a special honor).

So what is the difference between this plugin and all the other redirect management plugins? Well, this plugin is simple, safe, and straight to the point. Instead of using the WordPress options table to store redirects, it uses a custom post type; this is much more flexible and lighter on your server. The plugin has been tested and reviewed by multiple WordPress core contributors and is available on WordPress.com — in order for a plugin to be available on WordPress.com it must be extremely secure. Safe Redirect Manager also allows you to use regular expressions in your redirects (if you don’t know what this is, don’t worry it’s an optional feature).

Here is a screenshot:

Download here: http://wordpress.org/extend/plugins/safe-redirect-manager

P.S: If you are a developer, Safe Redirect Manager is available to be forked on Github.

Edit: Thank you Branco Radenovich for the Slovak translation. This will be included in version 1.6.1 of the plugin.

10up.com

May 22, 2012 by Taylor Lovett

Hey guys,

I’m starting a full time job for 10up as a Web Design Engineer. Exciting! In light of the new job. I’ve decided to change up TaylorLovett.com and move the blog to the front page. Soon I am trying to completely redo this site as it has gotten a little outdated.

Fields Disappearing Bug Fixed in Custom Contact Forms 4.0.9.5

January 14, 2011 by Taylor Lovett

Since the inception of Custom Contact Forms there has been a very strange bug that has bunch of people. After detaching fields in a certain order, fields would start to randomly disappear and blank spaces would pop up in the attachment dropdown. This was an error in logic. If two fields were attached to a form one with ID 1 and the other with 11, the fields would be stored in the database accordingly: 1,11, . Detaching the first field would remove instances of 1, from that string, but there are two instances of 1, in that string, some the resulting string would be 1 which would throw everything off from then on. This has been fixed by using serialization to store attached fields and field options. Also the Javascript Conflict bug has been fixed. If you are still experiencing this bug, simply disable jQuery on the frontend in “General Settings”.

Custom Contact Forms 4.1.0 is going to be released in the next week. It will have many new features such as a fixed field for states and countries as well as a dashboard widget for saved form submissions. We are in dire need of beta testers. If you are interested please fill out the following form:

Join the Custom Contact Forms Team

WordPress Frameworks or Parent Themes

August 13, 2010 by Taylor Lovett

WordPress frameworks are the wave of the future for not only WordPress users but also developers.

What are WordPress frameworks?
Wordpress frameworks provide a structure for developers to build off of containing a ton of great functionality. WordPress frameworks are the definition of not recreating the wheel. The release of WordPress 2.7 beckoned a revolutionary new feature, child themes. Child themes sometimes contain as little as a single style sheet file and build off of a parent theme (duh). The parent theme, or the framework, contains a basic HTML framework, a default plain looking style sheet, and most importantly loads of great functionality: a completey widgetized header, footer, homepage, and sidebar, some great widgets included the frameworks theme function file, and a great configuration page for the template (allowing you to choose primary and secondary navigation menus, choose SEO settings, exclude categories from the blog page, and much, much more) among other things.

Why use a WordPress framework?
As previously stated, why reinvent the wheel? Developers turn their nose at already developed frameworks because they feel they can do it better. I assure you this is not true. The functionality of these frameworks provides a versatility to WordPress that would take a year for any programmer to develop. Also, many parent themes provide a plethora of beautiful child themes to spiced up your site.

Top WordPress Framworks
Genesis: Developed by Studiopress, this is my go to framework and I use it on most of my clients websites. There are enough professional child themes to suite anyones tastes and everything is extremely easy Ito customize. The Genesis widgets are amazing and come preinstalled: add twitter to your menu, featured pages and posts with preview images (that you can define within the page or post!) and more. The SEO capabilities of Genesis make plugins like SEO all in one redundant. Also Genesis is compatible with every 3rd party plugin that I’ve ever tried which is important. This is definitely my favorite WordPress framework and is very affordable.

Thesis: Another great WordPress framework. It has a host of nice child themes to spice up your site. This framework also has a great configuration page with many of the same features as Genesis. It lacks the custom widgets that Genesis has. A means to manage SEO is also included in this framework. Where this framework is lacking is customization from the standpoint of the developer. The code is documented poorly compared to Genesis making it a constant battle to change anything code-wise. Thesis is also a little more expensive.

There are other great frameworks out there such as Thematic, but Genesis is my preference.