Amazed By Such A Great Support And Feedback!

WordPress-Christmas-19Today is our 19th day of our Advent Calendar and we just want to say thank you to our readers, who have given a great feedback to our tips on our Advent Calendar and we have quite a lot more people reading our blog since the start of our calendar, about 30% raise. We also like to thank for the big support of our sponsors, we are especially happy that our spots for ads are sold out for this month!

We are glad that our readers like our posts on WP Engineer and our sponsors recognizing the value of being displayed on WP Engineer. Just to get to know our sponsors a little bit better, we will introduce them shortly. We hope that you find the services and offers of our sponsors interesting and useful. All of them are WordPress or Design related, I guess a good fit for our readers:

WishList Member is a powerful membership script that can turn any WordPress blog into a full blown membership site. Very interesting, you have to check it out. WishList Member belongs to our loyal sponsors, we are very glad to have them and to provide our readers a great membership plugin.

wpSEO is a great Plugin for better SEO on your WordPress installation. Check it out and you will love it as Google will love your blog from now on. 😉 Of course we are using it on WP Engineer too. WP 2.9 ready and with over 70 setting to optimize your blog.

MakeBetterWebsites is a great gallery with a fine selection of high quality websites. All websites are handpicked and most of them I have first seen on this website instead of the usual suspects, seen on many other websites over and over again. Only high quality websites are seen on this website.

Pagelines-ThemesIf you also want to have a great design for your website, just get a PageLines Theme. They have superior themes for WordPress that make it simple for you to have an awesome, fully-featured website that is easy to set up and manage.

wpseek-searchOriginally was built as some kind of gateway for the little Firefox plugin "WordPress Helper" to handle all kinds of search requests.

You can add as a search engine in your favorite browser. Look at the upper right of your browser.

wordpress-bookDo you still need something for Christmas or it's too late for shipping or you even want to make yourself a great gift? Download this book, a great handbook to become a Pro in WordPress! 400 Pages of Practical Information. A Lifetime Subscription, when you buy this book, you will instantly get the most current version. But also, you are getting a lifetime subscription to all updated (PDF) copies of the book. And lots of Code Samples!

buckmaker-themeHere you'll find some of the most beautiful, powerful and state of the art WordPress Themes available these days. Their premium themes are very easy to install, edit and customize. They assist you in their support forums and provide several tutorials to get you started.

If you also interested to support our website, please go to and promote your service or product on WP Engineer. Maybe not this month, but maybe next month we have a spot just for you available. 🙂

Sort Posts With The Help Of Custom Fields

WordPress-Christmas-17Quite often, a WordPress developer likes to have posts sorted according to a custom field. If you would write a SQL-statement, it would be quite complex, since you need to JOIN two database tables (wp_posts und wp_postmeta).

But there is a much easier way, if you use the template tags provided by WordPress - in our case we use the function query_posts. Below you can see an example, which includes a custom field in the query, and also sort the posts with the help of this custom field. A short, easy to understand code with effective result:

Bildschirmfoto 2009-12-04 um 21.49.05


Guest Post

This post is written by Sergej Müller and is a post in our Advent Calendar on WP Engineer about WordPress.
Thank you very much from my part to Sergej.
If you also like to have your interesting post published on our website, please let us know on our contact page. Of course we will appreciate your contribution!

Display Private Posts to Logged in Users

WordPress-Christmas-15Sometimes I use the function of private posting in WordPress. These contributions can only see the user who has created the post, or the administrator. To show all these article to users who are logged into the system, you can go different ways. But I'd like to highlight just two different ways.

With custom fields

With the help of custom fields you create a private field; if you can see private posts, this field has true in the field. This field, we then query in the loop on output in the frontend.

if ( have_posts() ) :
	while ( have_posts() ) : the_post();
	// the loop
	$private = get_post_custom_values('private'); // read custom field
	if ( isset($private[0]) && $private == 'true' ) {
		if ( is_user_logged_in() ) {
			// display private post, only logged users
	} else {
		// display public post, for every visitors


With capabilities

Another method is, to assign via function capabilities to the appropriate role. You can do this with the help of a Plugin, for example Members, or just with a code snippet in functions.php of the theme. You have to call the snippet just once, after that you can delete it, since the capability is saved in the data base.

Ad capabilities to read private posts read_private_posts to the role of the author.

function fb_add_cap2role() {
	global $wp_roles;
	$wp_roles->add_cap('author', 'read_private_posts');
add_action( 'init', 'fb_add_cap2role' );

Also you can also remove the rights again. This is possible with the following solution:

function fb_remove_cap2role() {
	global $wp_roles;
	$wp_roles->remove_cap('author', 'read_private_posts');
add_action( 'init', 'fb_remove_cap2role' );

Use WordPress Cron

WordPress-Christmas-14WordPress has its own cron to automatically and scheduled run certain themes. Therefore WordPress provides several functions to use the cron.

In our first example we send every hour a mail with the help of the WordPress function wp_mail(). FYI, this is just a possibility, please don't do it on your system!

As default, WordPress can handle 3 time keys, which you can call with the function wp_schedule_event.

// send automatic scheduled email
if ( ! wp_next_scheduled('my_task_hook') ) {
	wp_schedule_event( time(), 'hourly', 'my_task_hook' ); // hourly, daily and twicedaily

add_action( 'my_task_hook', 'my_task_function' );
function my_task_function() {
		'Automatic mail', 
		'Hello, this is an automatically scheduled email from WordPress.'

If you use the cron in a Plugin or theme, then don't forget to deactivate the cron if you don't need it anymore.

delete_action( 'my_task_hook', 'my_task_deactivate' );
// clean the scheduler
function my_task_deactivate() {
	wp_clear_scheduled_hook( 'my_task_hook' );

But not always are 3 time values enough. Luckily you can expand the control via a filter.

add_filter( 'cron_schedules', 'filter_cron_schedules' );
// add custom time to cron
function filter_cron_schedules( $schedules ) {
	$schedules['once_half_hour'] = array( 
		'interval' => 1800, // seconds
		'display'  => __( 'Once Half an Hour' ) 
	return $schedules;