<?php wp_mail(‘jcamomile@pobox.com’, ‘test’, ‘The message’); ?>
Remove a filter
If you want to prevent a plugin or function from working on this template only, you can use this to remove the filter. Of course you need to find out the name of the filter first. This can be done by looking for the the add_filter functions in plugin. The example below removes the st_add_widget (share this) from the content <?php remove_filter(‘the_content’, ‘st_add_widget’); ?>
Echo Custom Field (Post Meta)
<?php echo get_post_meta($post->ID, ‘customfield’, true); ?>
What Template am I in?
Use in functions php. It outputs the name of the template file being used to display the current page. add_action(‘wp_head’, ‘show_template’); function show_template() { global $template; print_r($template); }
Check if user is Admin
Make something visible or invisible depending on whether logged in user is admin: <?php if ( is_user_logged_in() && current_user_can(‘manage_options’) ) { do_something(); } ?>
Links List (bookmarks) Advanced
Need to List a bunch of links, aka bookmarks, aka blogroll … This code comes in handy <?php $args = array( ‘orderby’ => ‘name’, ‘order’ => ‘ASC’, ‘limit’ => -1, ‘category’ => , ‘category_name’ => , ‘hide_invisible’ => 1, ‘show_updated’ => 0, ‘include’ => , ‘exclude’ => , ‘search’ => ); ?> <?php $bookmarks = get_bookmarks( $args ); // Loop through each bookmark and print formatted output foreach ( $bookmarks as $bm ) { printf( ‘<a class=”relatedlink” href=”%s”>%s</a><br />’, $bm->link_url, __($bm->link_name) ); } ?>
Hide Development Code before publishing
Cute way to partition off code that you are working on so that normal users don’t see it but you do. Simply add this conditional around your test code. Then on the test page, add ?iam=testing to the end of the url. <?php if ($_GET[‘iam’]==’testing’){ // code you are testing } ?>
Get Posts
This is a basic get_posts <?php $args = array( ‘numberposts’ => 5, ‘offset’ => 0, ‘category’ => 5, ‘orderby’ => ‘post_date’, ‘order’ => ‘DESC’, /* ‘include’ => , ‘exclude’ => , ‘meta_key’ => , ‘meta_value’ => , */ ‘post_type’ => ‘post’, /* ‘post_mime_type’ => , ‘post_parent’ => , */ ‘post_status’ => ‘publish’ ); ?> <?php $newsposts = get_posts( $args ); ?> <?php foreach($newsposts as $post) : setup_postdata($post); ?> // normal post tags and content <?php endforeach; ?>