This file contains hidden or 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
// http://wpsnipp.com/index.php/functions-php/add-youtube-thumbnail-posts-with-custom-metabox/ | |
add_action("admin_init", "youtube_init"); | |
add_action('save_post', 'save_youtube_link'); | |
function youtube_init(){ | |
add_meta_box("youtube", "Youtube thumbnail code", "youtube_link", "post", "normal", "high"); | |
} | |
function youtube_link(){ | |
global $post; | |
$custom = get_post_custom($post->ID); |
This file contains hidden or 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
<form role="search" method="get" id="searchform" action="<?php bloginfo('siteurl'); ?>"> | |
<div> | |
<label class="screen-reader-text" for="s">Search for:</label> | |
<input type="text" value="" name="s" id="s" /> | |
in <?php wp_dropdown_categories( 'show_option_all=All Categories' ); ?> | |
<input type="submit" id="searchsubmit" value="Search" /> | |
</div> | |
</form> |
This file contains hidden or 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
// http://wpsnipp.com/index.php/functions-php/attach-images-with-simple-thumbnail-selection-metabox/ | |
add_action("admin_init", "images_init"); | |
add_action('save_post', 'save_images_link'); | |
function images_init(){ | |
$post_types = get_post_types(); | |
foreach ( $post_types as $post_type ) { | |
add_meta_box("my-images", "Pictures", "images_link", $post_type, "normal", "low"); | |
} | |
} |
This file contains hidden or 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
// http://wpsnipp.com/index.php/posts/search-a-specific-post-type/ | |
function SearchFilter($query) { | |
if ($query->is_search) { | |
// Insert the specific post type you want to search | |
$query->set('post_type', 'feeds'); | |
} | |
return $query; | |
} | |
// This filter will jump into the loop and arrange our results before they're returned |
This file contains hidden or 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
// http://wpsnipp.com/index.php/functions-php/filter-search-results-by-post-type/ | |
function search_posts_filter( $query ){ | |
if ($query->is_search){ | |
$query->set('post_type',array('post','custom_post_type1', 'custom_post_type2')); | |
} | |
return $query; | |
} | |
add_filter('pre_get_posts','search_posts_filter'); |
This file contains hidden or 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
// http://wpsnipp.com/index.php/calendar/unregister-default-widgets/ | |
// unregister all default WP Widgets | |
function unregister_default_wp_widgets() { | |
unregister_widget('WP_Widget_Pages'); | |
unregister_widget('WP_Widget_Calendar'); | |
unregister_widget('WP_Widget_Archives'); | |
unregister_widget('WP_Widget_Links'); | |
unregister_widget('WP_Widget_Meta'); | |
unregister_widget('WP_Widget_Search'); |
This file contains hidden or 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
// http://wpsnipp.com/index.php/functions-php/add-select-menu-to-filter-by-custom-field-in-admin/ | |
add_filter( 'parse_query', 'ba_admin_posts_filter' ); | |
add_action( 'restrict_manage_posts', 'ba_admin_posts_filter_restrict_manage_posts' ); | |
function ba_admin_posts_filter( $query ) | |
{ | |
global $pagenow; | |
if ( is_admin() && $pagenow=='edit.php' && isset($_GET['ADMIN_FILTER_FIELD_NAME']) && $_GET['ADMIN_FILTER_FIELD_NAME'] != '') { | |
$query->query_vars['meta_key'] = $_GET['ADMIN_FILTER_FIELD_NAME']; | |
if (isset($_GET['ADMIN_FILTER_FIELD_VALUE']) && $_GET['ADMIN_FILTER_FIELD_VALUE'] != '') |
This file contains hidden or 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
// http://wpsnipp.com/index.php/functions-php/rewrite-the-search-results-slug-search-term/ | |
function search_url_rewrite_rule() { | |
if ( is_search() && !empty($_GET['s'])) { | |
wp_redirect(home_url("/search/") . urlencode(get_query_var('s'))); | |
exit(); | |
} | |
} | |
add_action('template_redirect', 'search_url_rewrite_rule'); |
This file contains hidden or 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
// http://wpsnipp.com/index.php/functions-php/track-post-views-without-a-plugin-using-post-meta/ | |
// functions.php | |
function getPostViews($postID){ | |
$count_key = 'post_views_count'; | |
$count = get_post_meta($postID, $count_key, true); | |
if($count==''){ | |
delete_post_meta($postID, $count_key); |
This file contains hidden or 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
// http://wpsnipp.com/index.php/template/create-multiple-search-templates-for-custom-post-types/ | |
/* | |
Create a new file called search.php and add the following search template. | |
Change the $search_refer= CUSTOM_POST_TYPE to the names of your post types. | |
You will also need to change the template path to the corresponding template you wish to display results. | |
*/ | |
<? | |
/* Template Name: Search Results */ |