wp_insert_post is automatically modifying my post content

The documentation for wp_insert_post() says: wp_insert_post() passes data through sanitize_post(), which itself handles all necessary sanitization and validation (kses, etc.). If we dig through it, we can find the responsible filter as: add_filter(‘content_save_pre’, ‘wp_filter_post_kses’); within the kses_init_filters() function. When the kses is initialized with kses_init() it runs: kses_remove_filters(); if ( ! current_user_can( ‘unfiltered_html’ ) ) … Read more

Change permalinks for post type ‘post’ only

I found the answer here. Remember to pop in there and give it a like. I’ll post it here, for people in a rush. Put this into the functions.php-file: function wp1482371_custom_post_type_args( $args, $post_type ) { if ( $post_type == “post” ) { $args[‘rewrite’] = array( ‘slug’ => ‘blog’ ); } return $args; } add_filter( ‘register_post_type_args’, … Read more

Show WordPress Custom Taxonomy Items Based On a Selected Item From Another Custom Taxonomy

Why not make the towns child terms of each state? The taxonomy could be location: See MikeSchinkel’s detailed q and a regarding hierarchal taxonomies. A more elegant solution than refreshing the page upon state selected would be to load the “thetown” child terms using ajax and the get_term_children function or the custom $wpdb query outlined … Read more

Listen to Post action

This is more of a JavaScript the A WordPress Question but anyway, You can use the JavaScript onbeforeunload event something like: <script type=”text/javascript”> old = window.onbeforeunload; window.onbeforeunload = MyOnExit; function MyOnExit(){ //do your stuff here return old(); } </script>

Related Posts by Multiple Tags?

I had the same idea and wrote a small little plugin to help me do this. function get_pew_related_data($args, $post_id, $related_id) { global $post, $wpdb; $post_id = intval( $post_id ); if( !$post_id && $post->ID ) { $post_id = $post->ID; } if( !$post_id ) { return false; } $defaults = array( ‘taxonomy’ => ‘topics’, ‘post_type’ => array(‘post’), … Read more

Skip post in loop and mixin later

What about an approach like this: $first_category_args = array( // category id ‘cat’ => 123, // get all from cat ‘posts_per_page’ => -1, // don’t prepend sticky ‘ignore_sticky_posts’ => 1, // only return ids ‘fields’ => ‘ids’ ); // array of ids $first_category_query = new WP_Query( $first_category_args ); $first_category_ids = $first_category_query->posts; $second_category_args = array( // … Read more

Portable Post Links

WordPress is strongly opinionated about using absolute URLs. Doesn’t mean it’s better but it’s a choice is makes. The common way to handle it is replace as necessary in database. Please note that if you run replacement on all of database it is extremely important to use serialize–aware tool, or you risk corrupting the data.

media_handle_upload for local files?

You want media_handle_sideload() Handles a side-loaded file in the same way as an uploaded file is handled by media_handle_upload(). // Array similar to a $_FILES upload array. $file_array = array( ‘name’ => ‘filename.jpg’, ‘tmp_name’ => ‘path/to/filename.jpg’, ); // Post ID to attach upload to, 0 for none. $post_id = 0; $attachment_id = media_handle_sideload( $file_array, $post_id … Read more

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