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

How to add option box in “Edit Post” plugin API?

Below is the example of a couple of checkboxes to set custom field values: // register the meta box add_action( ‘add_meta_boxes’, ‘my_custom_field_checkboxes’ ); function my_custom_field_checkboxes() { add_meta_box( ‘my_meta_box_id’, // this is HTML id of the box on edit screen ‘My Plugin Checkboxes’, // title of the box ‘my_customfield_box_content’, // function to be called to display … Read more

Custom permalink structure only for default posts

The solution is to reregister the default post type just after WordPress, and to add a rewrite slug. Also, the _builtin param needs to be set to false. add_action( ‘init’, ‘my_new_default_post_type’, 1 ); function my_new_default_post_type() { register_post_type( ‘post’, array( ‘labels’ => array( ‘name_admin_bar’ => _x( ‘Post’, ‘add new on admin bar’ ), ), ‘public’ => … Read more

How to add a new tab to page editor

I remembered that once I done this, yesterday I found where, but that code was… bad. So today I little improved it and I’m going to share. Before I want to explain what I do. First of all, there are 3 main things to do: Add the tab title beside the standard 2 Add something … Read more

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