Delete Child Posts

Try it like this: $args = array( ‘post_parent’ => $parentid, ‘post_type’ => ‘custom-type’ ); $posts = get_posts( $args ); if (is_array($posts) && count($posts) > 0) { // Delete all the Children of the Parent Page foreach($posts as $post){ wp_delete_post($post->ID, true); } } // Delete the Parent Page wp_delete_post($parentid, true);

How to Sort Custom columns in admin

This tutorial from WPTuts+ will do the trick … Quick Tip: Make Your Custom Column Sortable In a recent article by Claudio Simeone, he demonstrated how you could add extra columns to your post, or custom post type, admin screens (or remove existing ones). In this quick tip I build on that by showing you … Read more

Load posts dynamically

Here’s how I’d approach it. Let me know in the comments if you need more detail. 1) Create a template that pulls back your initial page content — the default right panel content and the list of links for the left panel. Ensure the links have post_id set as the value of the id attribute. … Read more

Disallow a user to post in certain categories

save_post is too late. Look at the source and you can see that the post has already been saved when that hook fires. You will have to interrupt the process well before that hook if you want to prevent saving. I think I would lean toward something like this: add_filter( ‘post_updated_messages’, function($messages) { $messages[‘post’][11] = … Read more

How to programmatically create posts in wordpress?

You can use the wp_insert_post() function to accomplish creating a new post, including it being in a draft state. As you can see in this snippet from the Codex, you can control all the aspects of the post, including post date, draft status, post type, categories, and much more. $post = array( ‘ID’ => [ … Read more

get_the_term_list by hierarchy order

get_the_term_list() will not work here. The best function to use would be wp_get_post_terms() With the following assumption, this can work If a post only belongs to one parent, one child and/or one grandchild, you can order the terms by term_id. It is widely accepted that the parent will have a lower numbered ID than the … Read more

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