best practice for query string values – get_query_var always empty for my value supplied in query string

You get the exact unchanged value with: $event_id = filter_input( INPUT_GET, ‘event_post_id’, FILTER_VALIDATE_INT ); Here I added the validation filter directly, but you can even move that to separate code for more complex cases. WordPress’ query variable handling is for cases in which you want to allow changes to the values before they reach your … Read more

Event Calendar using insert_post_data after save_post and insert_post after post_transition draft_to_schedule

Hi @user2271: I recently had to resolve a situation for an Event custom post type where I could not get WordPress to let me save a future date. I wasn’t trying to be as complex as yours but the follow code resolved my issue, maybe you can use it to resolve yours: add_action(‘admin_init’, ‘yoursite_admin_init’); static … Read more

How to hook into Add New Member in BuddyPress

In order to get the user id when a user is registered, hook into bp_core_signup_user: add_action(‘bp_core_signup_user’, ‘doMyFunction’, 10, 5); function doMyFunction($user_id, $user_login, $user_password, $user_email, $usermeta){ //do stuff } It supplies the user id as the first parameter.

When is the {$new_status}_{$post->post_type} transition hook fired?

It is fired in wp-includes/post.php on line 3026 in the following function: wp-includes/post.php: line 3014-3027 function wp_transition_post_status($new_status, $old_status, $post) { do_action(‘transition_post_status’, $new_status, $old_status, $post); do_action(“{$old_status}_to_{$new_status}”, $post); do_action(“{$new_status}_{$post->post_type}”, $post->ID, $post); }

Checking post format during xmlrpc_publish_post

This is because of a variable mismatch. Your function accepts $post_ID, but you don’t actually use it. You’re instead trying to reference a global $post object and doing your post format check with $post->ID. With the XML-RPC request, this won’t work. Rewrite your function to use get_post() to fetch a post object from the passed-in … Read more

How to delete all post and attachments of a user when I delete it?

The hook you choose is appropriate, and here is how to use it to delete all posts of all types (posts, pages, links, attachments, etc) of the deleted user: add_action(‘delete_user’, ‘my_delete_user’); function my_delete_user($user_id) { $args = array ( ‘numberposts’ => -1, ‘post_type’ => ‘any’, ‘author’ => $user_id ); // get all posts by this user: … Read more

How to prevent double execution of do_action statements

To check if someone already hooked into myhook1 if( 0 >= did_action( ‘myhook1’ ) ) do_action( ‘myhook1’, ‘myfunction1′ ); If you want to check if the function myfunction1 was already called (maybe by a simple function call), you have to set a ‘marker’ function myfunction1 ( $some_args ) { // with a simple global define … Read more