Extending WP_Query — Optimise SQL query

Here’s an idea, however it will require the ability to make custom SQL queries – with $wpdb.

Since you want to get posts followed by a user, you can create a view, with the following structure:

id user_id post_id post_title post_content ... (all other post fields)

don’t worry about duplicating posts.

When you select, you just have to do a simple select * from the_view where... .

Later you can cache results from this view using memcache or other object cache technique to make it faster.

Leave a Comment