Querying Custom Post Types with Page Navigation on Front Page

I was experimenting with displaying custom post types on the front page of a wordpress site using various methods. I had first tried using get_posts(), but it couldn’t deal with pagination. The next alternative was to use WP_Query(). At first I had tried to implement this in the home.php template, but next_posts_link() returned an error … Read more

Converting HTML entities to characters

I was trying to use WordPress post titles as email subject headers in such a way: $subject = get_the_title(); wp_mail( $to, $subject, $message); However this became a problem when the post title included smart quotes, em-dash, ellipsis and the likes of them. My email subject ended up looking like this: Hey – This is my Post’s Title where … Read more

WordPress 3.1 and setup_postdata

After upgrading one of my websites to WordPress to version 3.1, the loops that contained setup_postdata() created a mess. After some testing, I realised that setup_postdata() will only return the correct data if the argument passed is $post, i.e. setup_postdata($post). I had used setup_postdata( $ancestor ) instead and it created a mess after the upgrade. … Read more

Ways to load template files in WordPress

The below methods mostly uses get_template_directory() to retrieve the parent theme directory and get_stylesheet_directory() if you are using a child theme and retrieving the  of  child theme directory. Using include() and require() These are built-in PHP functions and you can use them to load template files like this. Note that they do not check file … Read more