Category Archives: Snippets
WP Snippet: .htaccess webfonts fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
WP Snippet: get hierarchical post ancestor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 ) ); | |
} |
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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'); |