Tag Archives: php

WP_Query and posts_per_page

21 Mar

Problem The following code does not seem to limit the posts to 3 posts.  Instead uses the wordpress setting of 10 posts: // The Query $the_query = new WP_Query( array( ‘nopaging’ => true, ‘posts_per_page’ => 3, ‘post_type’ => ‘post’ ) ); Wordpress codex says the posts_per_page will be overridden if it is on a feed. [...]

WordPress Maintenance Page

8 Mar

If you’ve updated WordPress, you should have noticed that wordpress goes into “maintenance mode” whenever mass plugins or WordPress itself is updated.  What if you wanted to do some manual upgrading?  Then you can manually put wordpress into maintenance mode. To put wordpress into maintenance mode, just add a .maintenance file (notice the leading dot) [...]

WordPress Cron

20 Dec

A great way to take more control of your wp-cron and also slightly speed up wordpress is to disable cron and scheduled a cron job on your server to run wp-cron.php.  You just need a server that supports cron jobs. In wp-config.php add: define(‘DISABLE_WP_CRON’, true); Be careful though, sometimes this has a negative effect on [...]

Hardening WordPress

18 Dec

I’ll be updating this post as I find more and better explanations to hardening wordpress.  The more secure, the better.  Some things to keep in mind when you are trying to secure your wordpress installation. Be careful when saying a security measure is “not worth the time” to do it.  If it takes 5 minutes [...]

How to use your own template for specific times

14 Dec

There’s a great post on how to get WordPress to use your own template and override the default template. The basic code looks like this; function my_template() { if (is_category() && get_query_var(‘cat’) == get_cat_id(‘fun’)) { include (TEMPLATEPATH . ‘/category-fun.php’); exit; } } add_action(‘template_redirect’, ‘my_template’);   Be sure to use STYLESHEETPATH instead of his TEMPLATEPATH so that child [...]

WP Query inconsistencies in query

6 Dec

Problem In WordPress, I created a new WP_Query with a few simple args to get a custom post type.  However, no results came back.  I could look at the query by checking WP_Query’s request property.  The query, when run in mysql returned the desired rows.  So what was happening to these rows?   Solution WP_Query’s posts [...]

Optimize Custom WordPress Queries

20 Nov

A couple things that may optimize your custom wordpress queries.  First there is a parameter called ‘fields’ where  you can specify that you only want the ID field back.  Something like below: $some_query = new WP_Query( array( ‘fields’ => ‘ids’ ) ); An even more significant optimization is by caching your data and using WordPress’ [...]

Buddypress User Ids

16 Nov

Buddypress has several methods to get the user ids.  This post attempts to clarify the differences between these: bp_current_user_id - Exactly the same as bp_displayed_user_id.  This is possibly an old, now renamed, method. bp_loggedin_user_id – The buddypress logged in user id. bp_displayed_user_id – this will return the user id of the user that you are looking [...]