Categories
WordPress

Display Contact Form 7 acceptance checkbox error message

Add following line to your Contact Form 7 forms Additional Settings field
acceptance_as_validation: on

Categories
WordPress

Regenerate thumbnails with WP-CLI

You can easily regenerate thumbnails with WP-CLI, just type $ wp media regenerate --yes in the command line.

The --yes flag answers yes to the confirmation message.

WP-CLI documentation

Categories
PHP WordPress

Get human readable time difference in WordPress

Display posts dates as 2 days ago instead of regular date.

Documentation

Categories
PHP WordPress

Save WP_Query results to a variable

$the_query = new WP_Query( array(...) );
$posts = $the_query->get_posts();

Categories
PHP WordPress

Order WordPress posts by multiple keys

In WordPress 4.0+ WP_Query argument orderby accepts arrays, so posts can be ordered by multiple keys and orders.
In example

Categories
PHP WordPress

Get select fields options from Types custom field

Now your data is formatted in array with key as display text and value as custom field content
array(
'Display text' => 'Custom field content',
'...' => '...',
'...' => '...',
'...' => '...',
)

Categories
JavaScript PHP WordPress

Add localized JavaScript variables to WordPress theme

Add following code to your functions.php

Added variable can be found in i18n object.

Categories
WordPress

Search and replace content with WP-CLI

$ wp search-replace '[shortcode_1]' '[shortcode_2]' wp_posts --skip-columns="post_title,post_name"
Replaces [shortcode_1] with [shortcode_2] from wp_posts table and skips columns post_title and post_name. Add --dry-run flag if you want to see the results without applying changes.

Categories
JavaScript WordPress

Using WP Rest API with Angular.js

View demo dev.viklund.fi/wp-rest-api. Full source can be found at Github

Below is a WordPress Rest API 2 filter to add sibling information to posts for easing navigation.

Categories
PHP WordPress

WordPress loop post count

$wp_query->post_count contains number of posts being displayed.
$wp_query->found_posts contains total number of posts found with current criteria.