Sort posts by newest child while keeping hierarchy intact

How do you retrieve and echo this structure in first place? I don’t think you can query by something like this (without some wicked SQL), so it would be probably easier to: Retrieve parent posts. Look up newest child (query, sort by date, limit to one). Reorder parent posts accordingly.

A way to detect which page a post is on

Alright, nevermind. I got this solved by doing this at the top of the single post template: $position_query = array( ‘post_type’ => ‘portfolio’, ‘orderby’ => ‘menu_order’, ‘order’ => ‘ASC’, ‘numberposts’ => -1 ); $position_posts = get_posts($position_query); $count = 0; foreach ($position_posts as $position_post) { $count++; if ($position_post->ID == $current_id) { $position = $count; break; } … Read more

All my inserted images gets a link to the full image even if it is already full size image

The following code will empty the Link URL field when Full Size button is clicked. And fill the same field with the File URL value when other buttons are clicked. Tested with WordPress 3.4.2. Drop the code in your theme’s functions.php file or create a simple plugin for it. add_action( ‘admin_head-media-upload-popup’, ‘wpse_41539_add_remove_image_url’ ); function wpse_41539_add_remove_image_url() … Read more

Autoremove empty custom fields

I believe this was my solution to a previous question you had. I mentioned in that answer that the code didn’t deal with the eventuality of a key with multiple values and only some of which are empty. The reason why is how WordPress treats delete_post_meta… When using delete_post_meta, the first two arguments specify the … Read more

Making post views as sortable

The posts_column_register_sortable function, hooked onto posts_column_register_sortable returns an array with names of sortable columns as keys and their corresponding value what to sort by (e.g. ‘post_title’ etc). In your case you’ve given it ‘post_views’ to sort by, which doesn’t exist as a column – so you need to tell WordPress how to sort by it. … Read more