Determine Term depth

Not trying to bump my rep, but I found my own answer. get_ancestors allows you to get the hierarchy of any item. Since terms can only have 1 parent, this is all we need: the number of items in this list equates to the term depth level, and even provides term ids. Usage: $ancestors = … Read more

Get top level page parent title

Found this way: if ( 0 == $post->post_parent ) { the_title(); } else { $parents = get_post_ancestors( $post->ID ); echo apply_filters( “the_title”, get_the_title( end ( $parents ) ) ); } Anyone got a better way please answer.

How to Check if a Page Exists by URL?

You could make a list of paths to check… $page_paths = array( ‘analysis/firstNamelastName’, ‘exercise/firstNamelastName’ ); Then check if there’s a page object for each of the page paths. foreach( $page_paths as $page_path ) { echo ‘<code>’ . $page_path . ‘</code> ‘ . PHP_EOL; if( ! $page = get_page_by_path( $page_path ) ){ echo ‘Does not exist.’ … Read more

Change custom post type to hierarchical after being registered

And as it usually happens, I find the answer a few minutes after posting the question… So here’s what I did in my theme’s functions.php file to solve my problem: function modify_products() { if ( post_type_exists( ‘product’ ) ) { /* Give products hierarchy (for house plans) */ global $wp_post_types, $wp_rewrite; $wp_post_types[‘product’]->hierarchical = true; $args … Read more