Grabbing how Many Posts by Month for a Dashboard Widget

Just Went over your code and it looks fine but you are missing the code blocks for your foreach loops so: add_action(‘wp_dashboard_setup’, ‘dashboard_test’); function dashboard_test() { global $wp_meta_boxes; wp_add_dashboard_widget(‘month_dashboard’, ‘Reports Submitted for the Year’, ‘custom_test’); } function custom_test(){ global $wpdb; $years = $wpdb->get_col(“SELECT DISTINCT YEAR(post_date) FROM $wpdb->posts WHERE post_status=”publish” AND post_type=”report” ORDER BY post_date DESC”); … Read more

!is_admin() condition turns true in admin pages

redirecting not logged in user is the only thing that works 🙂 in the backend. What you are describing is very peculiar. template_redirect is a front-end hook. Your code will never run on the backend, as far as I can tell. You can demonstrate that with this line: add_action(‘template_redirect’,function() {die;}); You can traverse the back-end … Read more

Conditional for autosave or auto draft?

If you are using the save_post action hook; then you can prevent the code from executing during an autosave with the following conditional: function do_not_autosave( $post ) { // Check to see if we are autosaving if (defined(‘DOING_AUTOSAVE’) && DOING_AUTOSAVE) return; // Rest of the code here } add_action( ‘save_post’, ‘do_not_autosave’);

WP_query hooks before execute a search query

To avoid the splitting of searchphrases, use the sentence query variable in the pre_get_posts hook: function only_search_for_full_phrase( $query ) { if ( $query->is_search() && $query->is_main_query() ) { $query->set( ‘sentence’, true ); } } add_action( ‘pre_get_posts’, ‘only_search_for_full_phrase’ ); Didn’t test it, but should do the trick. Happy Coding!

How to check if a protected hook is hooked?

As noted in my answer to your related question there is a datastructre $wp_filter that stores all information on hooks and filters. You may want to try a var_dump on it just to see what it looks like. There is no built in variable ‘protected’. This leaves you with two options to keep the administration … Read more