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
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.

Categories
PHP WordPress

Passing variables to get_template_part() template in WordPress

Local variables are not available in get_template_part() templates.

Instead of using global variables, template can be included with locate_template() function and all your variables will be available in the template file.

Categories
PHP WordPress

Display different number of posts per page in the archives

Add following code to your functions.php.

$query->set( 'posts_per_page', -1 ); shows all posts.

Above example does not work in Page requests, use query_posts() instead.

Categories
PHP WordPress

Get current URL in WordPress

To get current url in WordPress with arguments use the following function.

Categories
PHP WordPress

Get post thumbnail URL in WordPress

Returned array contains values for url (0), width (1), height (2) and scale (3).

Categories
PHP WordPress

WP_Query with a date filter on a custom field

Select posts where custom field wpcf-start-date is larger or equal as current date.

Categories
PHP WordPress

Enable tags for WordPress pages

Add the following snippet to your themes functions.php file.

Categories
PHP WordPress

Remove WordPress gallery shortcodes default styles

Add following snippet to your themes functions.php