Custom rewrite rule for hierarchical custom post type

You’re pretty close. Your rewrite rule is using the wrong query var, pagename should be just name. Here’s a version that works for me on a fresh 4.4.1 install and twentysixteen theme- function bvt_product_init() { $args = array( ‘label’ => __( ‘Product’, ‘domain’ ), ‘description’ => __( ‘Company products’, ‘domain’ ), ‘supports’ => array( ‘title’, … Read more

Show siblings (if any) and parents

As it stands your code almost works, but it checks to see if the current page has a parent, which will always be true for both 2nd and 3rd level pages. WordPress gives us get_ancestors to retrieve an ordered array of ancestors for any hierarchical object type: get_ancestors( $object_id, $object_type ); So we can use … Read more

How do I list the child of a child page [duplicate]

First of all, why you are querying for posts by your custom query? We have WP_Query class and get_posts function to do this. $child_pages = $wpdb->get_results(“SELECT * FROM $wpdb->posts WHERE post_parent = “.$post->ID.” AND post_type=”page” ORDER BY menu_order”, ‘OBJECT’); became $pages = get_posts(array( ‘post_type’ => ‘page’, ‘orderby’ => ‘menu_order’ ‘order’ => ‘ASC’ ‘posts_per_page’ => -1, … Read more

remove/hide pages from users backend

One way to achieve this is by looping through the parent pages and fetching their respective children pages ids. The resulting arrays can then be merged and used in the ‘post__not_in’ variable. add_filter( ‘parse_query’ , ‘exclude_pages_from_admin’ ); function exclude_pages_from_admin( $query ) { global $pagenow,$post_type; $pages = array(‘1′,’2′,’3’); foreach ( $pages as $parent_page ) { $args … Read more

Need wp_query to return all children and grandchildren

Ok, I found a solution. I first looped through and got all the child page ID’s, created an array, and used post_parent__in <?php $parentarray = array($parentid); $parentposts = new WP_Query( array( ‘posts_per_page’ => -1, ‘post_type’ => ‘page’, ‘post_parent’ => $parentid ) ); while ( $parentposts->have_posts() ): $parentposts->the_post(); ?> <?php $parentarray[] = get_the_id(); ?> <?php endwhile; … Read more

Pagination of a WP_Query Loop in a child-page page template

Glad that you managed to figure out a solution, which yes, does work. But you could make it more selectively, i.e. target just the specific pages, by using is_single( ‘<parent slug>/<child slug>’ ), e.g. is_single( ‘family-law/success-stories’ ) in your case. Secondly, it’s not exactly the redirect_canonical hook which caused the (301) redirect on singular paginated … Read more