Delete child post and attachment links to parent post

There’s no way of doing this without “listening” for the responsible database query and altering it with the query filter, thanks to this line in wp_delete_post(): // Point all attachments to this post up one level $wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( ‘post_type’ => ‘attachment’ ) ); The following will override the query and set … Read more

List child categories from parent category on custom taxonomy page

Two things! 1) Don’t use query_posts()! Instead, for situations like this, use the pre_get_posts action to modify the query. 2) I don’t think you actually want to be using a loop here at all (so neither query_posts() nor pre_get_posts or even WP_Query). Rather, I think you’re looking for wp_list_categories. In your template, you’d probably do … Read more

Query all post types but limit to parents

In your functions.php you can create a function that will hook into the pre_get_posts hook. Something like (just an example): function alter_query($query){ $query->set(‘post_parent’, 0); } add_action( ‘pre_get_posts’, ‘alter_query’ ); There you can alter the main query. That way while(have_posts()) : the_post(); will still just normally work. (You should check if you are altering the right … Read more

Migrating Hierarchal Taxonomy Categories Between Post Types

So that at least there’s a solution here, will add that this plugin seems to succesfully migrate Posts as well as category and hierarchy.: https://wordpress.org/plugins/post-type-convertr. On the production server, I also needed to run the following SQL query after migrating with the Post Type Convertr plugin: UPDATE wp_term_taxonomy SET taxonomy=’project-category’ WHERE taxonomy=’product_cat’; I dunno. Sorry … Read more