Function to execute when a post is moved to trash .

This will do the trick! add_action(‘trash_post’,’my_trash_post_function’,1,1); function my_trash_post_function($post_id){ if(!did_action(‘trash_post’)){ // do stuff } } Here we add the function, and to prevent the hook from executing more than once using did_action: http://codex.wordpress.org/Function_Reference/did_action As always, these kinds of hooks take the form {post_status}_{post_type}, so trash_post, trash_page, trash_customposttype, publish_page etc

How to get post creation date?

The post_date and post_date_gmt serves as the date that the post was created. For scheduled posts this will be the date on which the post is scheduled to be published. There is no reliable native method to determine the date when a scheduled post was added. For scheduled posts, you can try the post_modified or … Read more

Get post content by ID

You can do it multiple ways. Following are best two ways. $post_id = 5// example post id $post_content = get_post($post_id); $content = $post_content->post_content; echo do_shortcode( $content );//executing shortcodes Another method $content = get_post_field(‘post_content’, $post_id); echo do_shortcode( $content );//executing shortcodes After Pieter Goosen suggestion on apply_filters. You can use apply_filters if you wanted the content to … Read more

Rewriting post slug before post save

The following is to be taken more as a proof of concept rather than a copy/paste-ready solution. That being said, this is how you’d go about it: The save_post action runs whenever a post is updated or created. You can hook a callback function to it using add_action. Hence, your case would have to look … Read more

Add custom Attachment Display Setting for images

This will add a field in the attachment edit screen for applying a class to the img tag. function IMGattachment_fields($form_fields, $post) { $form_fields[“imageClass”][“label”] = __(“Image Class”); $form_fields[“imageClass”][“value”] = get_post_meta($post->ID, “_imageClass”, true); return $form_fields; } add_filter(“attachment_fields_to_edit”, “IMGattachment_fields”, null, 2); function my_image_attachment_fields_save($post, $attachment) { if ( isset($attachment[‘imageClass’]) ) update_post_meta($post[‘ID’], ‘_imageClass’, $attachment[‘imageClass’]); return $post; } add_filter(“attachment_fields_to_save”, “my_image_attachment_fields_save”, null, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)