Child Pages Loop

I’m fairly certain the problem is that some template tags rely on the global $post variable. Using setup_postdata() as you are now, will not alter $post. If you replace all the instances of $pageChild with $post, everything should work. However, I would strongly recommend using the WP_Query class and setting up your post data with … Read more

Is there a default template file for child pages / subpages?

There is no specifica template for child pages, but you can do this pretty easily with the get_template_part() function. First create a file called “content-child.php”. Second create a file called “content.php”. Next, inside of page.php, place this: if( $post->post_parent !== 0 ) { get_template_part(‘content’, ‘child’); } else { get_template_part(‘content’); } Anything that you want displayed … Read more

Allow only new sub-pages to be created

you actually don’t need any ajax or server side action, simple see if the user has selected a parent page: add_action( ‘admin_head-post-new.php’, ‘publish_admin_hook_wpse_78690’ ); add_action( ‘admin_head-post.php’, ‘publish_admin_hook_wpse_78690’ ); function publish_admin_hook_wpse_78690() { global $current_screen; if( ‘page’ != $current_screen->post_type ) return; ?> <script language=”javascript” type=”text/javascript”> jQuery(document).ready(function() { jQuery(‘#publish’).click(function() { var parent_id = jQuery(‘#parent_id’).val(); if (parseInt(parent_id) > 0){ … Read more

Display a list of child posts on parent posts of a custom post type

The best way is using WP_Query. I think your error or plugin error could be that the ‘post_type’ of childs is not define. WP Query : https://codex.wordpress.org/Class_Reference/WP_Query global $post; $args = array( ‘post_parent’ => $post->ID, ‘posts_per_page’ => -1, ‘post_type’ => ‘products’, //you can use also ‘any’ ); $the_query = new WP_Query( $args ); // The … Read more

Automatically create child pages when saving a (parent) page

Use the save_post action to run some code when a new show is created, then use wp_insert_post to create your child pages. Here’s an example to get you started – First, filter out any saves that are auto-saves, post revisions, auto-drafts, and other post types. Once you know it’s your show type, you can check … Read more