WP Snippet: .htaccess webfonts fix


# BEGIN REQUIRED FOR WEBFONTS
AddType font/ttf .ttf
AddType font/eot .eot
AddType font/otf .otf
AddType font/woff .woff
<FilesMatch "\.(ttf|otf|eot|woff)$">
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
</FilesMatch>
# END REQUIRED FOR WEBFONTS

view raw

.htaccess

hosted with ❤ by GitHub

WP Snippet: get hierarchical post ancestor


/**
* get hierarchical post ancestor (level 0)
*
* @param int|object $post
* @return object post ancestor
*
* @usage get_post_ancestor(131) | get_post_ancestor($post)
*
**/
function get_post_ancestor( $post = false ) {
if ( !is_object($post) ) {
$post = get_post($post);
}
if ( !$post || empty($post->ancestors) ) {
return;
}
return get_post( end( $post->ancestors ) );
}

view raw

functions.php

hosted with ❤ by GitHub

WP Snippet: Include custom post meta in WordPress search

Following this article i think is a litte old, here i bring an improved code.

This function allows include any post_meta in search query.


/**
* adds meta values on search query
*
* @param object $query
*
**/
function custom_search_query( $query ) {
if ( !is_admin() && $query->is_search ) {
$query->set('meta_query', array(
array(
'key' => '__meta_key__',
'value' => $query->query_vars['s'],
'compare' => 'LIKE'
)
));
// you can add additional params like a specific 'post_type'
// $query->set('post_type', 'project');
};
}
add_filter( 'pre_get_posts', 'custom_search_query');

view raw

gistfile1.aw

hosted with ❤ by GitHub