Retrieving taxonomy terms belonging to a set of posts

This issue comes up often, where I need to show a list of all terms belonging to a set of posts being queried. One useful case would be to allow the user to filter the queried posts by clicking on a ‘term’ from the generated list of terms. Let’s say we are on a taxonomy-term … Read more

Caldera Forms – Setting up Conditional Logic based on a post’s taxonomy term

I was trying to set up the following using Caldera Forms’ Conditional Group. This log is based on Caldera Forms 1.7.2. In my form, I needed a Select field X that was auto populated with a list of every post of a custom post type. This can be easily achieved by selecting ‘Auto Populate’ and … Read more

Changing ‘Stock Availability’ Text for Product Variations

This documents one method to change the ‘Stock Availability’ text for Woocommerce Product Variations. My requirement was that when a Product Variation was selected by the user on the frontend, in the following instances I wanted to show the corresponding availability text: Available: ‘[number] units available for your purchase.’ instead of the default ‘Available’. Out … Read more

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

Adding Custom Styles Dropdown in WordPress TinyMCE Editor

I have been trying out a WordPress plugin called WP Code Prettify to make code snippets on this website look more presentable. Previously, I was simply using <pre> or <code> tags without any styling and it was difficult to read. Well, WP Code Prettify will automatically style all <pre> or <code> tags specified with the … Read more

Next and previous post link in same custom taxonomy

Until now, if you use next_post_link(‘%link’, ‘%title’, true) or previous_post_link(‘%link’, ‘%title’, true) to get the adjacent post for a custom post type which has a taxonomy assigned to it, it doesn’t work as intended. This is because these two functions are based on get_adjacent_post() which is hardcoded to look to the taxonomy ‘category’. So hard … Read more

get_header_image() returns null

While working on a theme in wordpress 3.4.2, I realised that wordpress function get_header_image() returns null in a ‘mu-plugins’ plugin even though in the theme’s functions.php file I’ve set a ‘default-image’ like this: add_theme_support( ‘custom-header’, array( ‘default-image’ => get_template_directory_uri() . ‘/subdir/default-header-image.jpg’ ) ); In the theme template file header.php, I’ve called get_header_image(), and it returns … Read more

WordPress Tinymce Dialogs

If you are trying to implement tinymce for your theme options page or plugins and the Insert/edit link doesn’t pop up the dialog after the button is clicked, try this: add_action( ‘admin_print_footer_scripts’, ‘wp_tiny_mce_preload_dialogs’, 30 ); add_action( ‘tiny_mce_preload_dialogs’, ‘wp_link_dialog’, 30 ); This worked for me as of version 3.1.3.

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 &#8211; This is my Post&#8217;s Title where … Read more

Extend WordPress Login Expiration

The default login session cookie is 48 hours. Although it’s usually enough for most users, it can be frustratingly short for developers and administrators. Here’s something useful for those who do not want the hassle of logging in now and then. Add this to your theme’s functions.php , or create a php file and load it … Read more