post_parent in custom post type

Hook in when a post is deleted, check for the post type, then manipulate post_parent of potential child posts (or delete the posts): function wp_dev_174635_update_posts( $parent_id ) { $parent = get_post( $parent_id ); if ( $parent->post_type !== ‘type2’ ) { return; } $posts = get_posts( array( ‘post_type’ => ‘type1’, ‘post_parent’ => $parent_id, ) ); foreach … Read more

Programmatically change post visibility on save_post action return a 500

There is some information about this problem in the Action Reference for save post: If you are calling a function such as wp_update_post that includes the save_post hook, your hooked function will create an infinite loop. To avoid this, unhook your function before calling the function you need, then re-hook it afterward. So something like … Read more

WPDB for post count on post

The problem you are having is that get_queried_object returns results based on the query that was run. On author.php, the queried object was an author. On single.php, page.php, or any custom post type template, the queried object will be the post, not the author. This means that if you want to use $wp_query->get_queried_object();, you will … Read more