How to enqueue scripts on custom post add/edit pages?

You can do it like this (put in your functions.php) : function add_admin_scripts( $hook ) { global $post; if ( $hook == ‘post-new.php’ || $hook == ‘post.php’ ) { if ( ‘recipes’ === $post->post_type ) { wp_enqueue_script( ‘myscript’, get_stylesheet_directory_uri().’/js/myscript.js’ ); } } } add_action( ‘admin_enqueue_scripts’, ‘add_admin_scripts’, 10, 1 );

How to test wp_cron?

My favorite plugin for that is Core Control which has very nice module for display of what is going in the cron – which events are set up, when are they next firing, etc. On getting your hands dirty level see _get_cron_array(), which returns internal stored data for cron events (top level of keys are … Read more

how to limit search to post titles?

Here’s a filter that’ll do the trick. Drop it into your theme’s functions.php or a plugin. /** * Search SQL filter for matching against post title only. * * @link http://wordpress.stackexchange.com/a/11826/1685 * * @param string $search * @param WP_Query $wp_query */ function wpse_11826_search_by_title( $search, $wp_query ) { if ( ! empty( $search ) && ! … Read more

Get a list of all registered actions

Filters and actions are both assigned to hooks. Functions assigned to hooks are stored in global $wp_filter variable. So all you have to do is to print_r it. print_r($GLOBALS[‘wp_filter’]); PS. add_action function makes a add_filter call. And the latter does $wp_filter[$tag][$priority][$idx]. NOTE: you can directly add this code in functions.php, and you will see a … Read more

Why does save_post action fire when creating a new post?

When you click ‘New Post’, you’re simply loading the page wp-admin/post-new.php. In doing so, WordPress will always create a new post (an ‘Auto Draft’) to ensure all other features (such as media uploads) and plugins work as normal, even before you actually save a draft or publish the post. And this, in turn, triggers save_post. … Read more

How to know what functions are hooked to an action/filter?

Look into the global variable $wp_filter. See my plugin for a list of all comment filters for an example: <?php /* Plugin Name: List Comment Filters Description: List all comment filters on wp_footer Version: 1.1 Author: Fuxia Scholz License: GPL v2 */ add_action( ‘wp_footer’, ‘list_comment_filters’ ); function list_comment_filters() { global $wp_filter; $comment_filters = array (); … Read more