Perform an action when post is updated/published

The save_post action fires When a post is updated and/or published — including when a new post is inserted. <?php add_action( ‘save_post’, ‘wpse41912_save_post’ ); function wpse41912_save_post() { // do stuff } If you want your functions to fire only when a post is being edited, you can hook into edit_post. If you want it to … Read more

How to use the do_action () with parameter

The correct way is to pass first argument as a unique string which acts as an identifier for the action & any additional arguments after that do_action(‘unique_action_tag’, $parameter1, $parameter2,,,, & so on); To attach functions to this action you’ll do // 10 is the priority, higher means executed first // 2 is number of arguments … Read more

Does hooking into the same action multiple times drain memory?

I guess you mean add_action( ‘pre_get_posts’, ‘private_groups’ ); add_action( ‘pre_get_posts’, ‘search_results’ ); add_action( ‘pre_get_posts’, ‘name_profiles’ ); versus add_action( ‘pre_get_posts’, ‘combined_into_single_callback’ ); You can just check the difference using e.g. memory_get_usage() and timer_stop(). Many good plugins out there to help with that. I would say go with the first one, as they seems to be unrelated … Read more

Possible to search by author name with default WordPress search function?

Maybe you can try adding your condition directly in the query string, using something like this function wpse_29570_where_filter($where){ global $wpdb; if( is_search() ) { $search= get_query_var(‘s’); $query=$wpdb->prepare(“SELECT user_id FROM $wpdb->usermeta WHERE ( meta_key=’first_name’ AND meta_value LIKE ‘%%%s%%’ ) or ( meta_key=’last_name’ AND meta_value LIKE ‘%%%s%%’ )”, $search ,$search); $authorID= $wpdb->get_var( $query ); if($authorID){ $where = … Read more

What is the difference between get_page_link and get_permalink functions?

When i explored the WordPress core for this answer i found that get_permalink() function internally calls get_page_link() function for getting permalink of page and it calls get_post_permalink() function to get permalink of post. Therefore either you use get_permalink() function or get_page_link() function, you will get same result. The difference between these two is get_page_link() function … Read more

Redeclare a function in a child theme

Redeclaring a function in a child theme only works when the parent themes’ function is wrapped in a if( !function_exists( ‘function_name’ )): condition. Then you can simply just copy the complete function to the child theme and do whatever modifications you need to do. If the parent themes’ functions aren’t wrapped in that if conditional … Read more