List of child custom post types lists all custom post types
I think you’re confusing WP_Query with taxonomy arguments. WP_Query doesn’t have a child_of argument, use post_parent. and sort_column should be orderby.
I think you’re confusing WP_Query with taxonomy arguments. WP_Query doesn’t have a child_of argument, use post_parent. and sort_column should be orderby.
This can be approached by using wp_dropdown_pages() with the child_of parameter. global $post; $args = array( ‘child_of’ => $post->ID ); wp_dropdown_pages( $args ); The variable name will be $_GET[‘post_id’] or $_POST[‘post_id’], depending on your form settings, you can change the name by altering the name parameter. The value of the variable is the ID of … Read more
Option 1: Personally I prefer this, because it gives you more options in the long run. Especially considering other setups involving a secondary query, take a look at my other answer I linked below. What you need to do is, make use of the paged parameter WP_Query offers. Additionally you have to setup a variable … Read more
You can use get_pages( array( ‘child_of’ => page_id ) ) to get all sub-pages.
You need to add a rewrite rule to WordPress. There are several options to do it depending on your exact needs. Maybe the most general is using add_rewrite_tag() and add_rewrite_rule(): add_action( ‘init’, ‘cyb_rewrite_rules’ ); function cyb_rewrite_rules() { add_rewrite_tag( ‘%variable1%’, ‘([^&]+)’ ); add_rewrite_tag( ‘%variable2%’, ‘([^&]+)’ ); add_rewrite_rule( ^system/([^/]*)/([^/]*)/?’, ‘index.php?pagename=$matches[1]&variable1=$matches[2]&variable2=$matches[3]’, ‘top’ ); } Now, if the URL … Read more
You can make all sorts of selections using wp_query. In your case try this: $query = new WP_Query (array( ‘post_parent’ => 93 // get the children of page with ID 93 ‘post_count’ => 7 // get 7 child pages ‘orderby’ => ‘rand’ // order the results randomly )); Once you have this, you can loop … Read more
the_dramatist’s answer will give you only top-level pages that have no children, which matches the example given in your description. However, if you want to get ALL leaf pages, use the following: SELECT * FROM $wpdb->posts WHERE post_type=”page” AND ID NOT in ( SELECT ID FROM $wpdb->posts WHERE post_type=”page” AND ID in ( SELECT post_parent … Read more
This should work. I’m not entirely sure what is wrong with your code (it’s getting late) but the below code works on my end. Obviously I replaced $order->get_id() with a known ID and post_type was set to page. <?php $parentid = $order->get_id(); $child = new WP_Query( array(‘post_parent’ => $parentid, ‘post_type’ => ‘shop_subscription’) ); if ($child->have_posts()) … Read more
If an ID is passed to get_the_title() or get_permalink(), they will use get_post() internally to get a copy of the full post object with that ID. But if get_post() is passed either nothing or a “falsy” value, like 0, then it will return the current global $post object. In the context of your code this … Read more
$args = array( ‘post_status’ => ‘publish’, ‘post_parent’ => $post_id ); $children = get_posts( $args ); if( count( $children ) > 0 ) { //has children } else { //does not have children } Docs: get_posts() This should also allow you to have access to the data of the children, should you need it. If you … Read more