is_post_type_hierarchical example

// Page-related Meta Boxes. //
/** * Displays page attributes form fields. * * @since 2.7.0 * * @param WP_Post $post Current post object. */
function page_attributes_meta_box( $post ) {
    if ( is_post_type_hierarchical( $post->post_type ) ) :
        $dropdown_args = array(
            'post_type'        => $post->post_type,
            'exclude_tree'     => $post->ID,
            'selected'         => $post->post_parent,
            'name'             => 'parent_id',
            'show_option_none' => __( '(no parent)' ),
            'sort_column'      => 'menu_order, post_title',
            'echo'             => 0,
        );

        /** * Filters the arguments used to generate a Pages drop-down element. * * @since 3.3.0 * * @see wp_dropdown_pages() * * @param array $dropdown_args Array of arguments used to generate the pages drop-down. * @param WP_Post $post The current post. */
$post_type = 'post';
        }

        if ( is_array( $post_type ) ) {
            if ( count( $post_type ) > 1 ) {
                return;
            }
            $post_type = reset( $post_type );
        }

        // Do not attempt redirect for hierarchical post types.         if ( is_post_type_hierarchical( $post_type ) ) {
            return;
        }

        $id = _find_post_by_old_slug( $post_type );

        if ( ! $id ) {
            $id = _find_post_by_old_date( $post_type );
        }

        /** * Filters the old slug redirect post ID. * * @since 4.9.3 * * @param int $id The redirect post ID. */

    do_action( 'before_delete_post', $postid$post );

    delete_post_meta( $postid, '_wp_trash_meta_status' );
    delete_post_meta( $postid, '_wp_trash_meta_time' );

    wp_delete_object_term_relationships( $postidget_object_taxonomies( $post->post_type ) );

    $parent_data  = array( 'post_parent' => $post->post_parent );
    $parent_where = array( 'post_parent' => $postid );

    if ( is_post_type_hierarchical( $post->post_type ) ) {
        // Point children of this page to its parent, also clean the cache of affected children.         $children_query = $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_parent = %d AND post_type = %s", $postid$post->post_type );
        $children       = $wpdb->get_results( $children_query );
        if ( $children ) {
            $wpdb->update( $wpdb->posts, $parent_data$parent_where + array( 'post_type' => $post->post_type ) );
        }
    }

    // Do raw query. wp_get_post_revisions() is filtered.     $revision_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'revision'", $postid ) );
    // Use wp_delete_post (via wp_delete_post_revision) again. Ensures any meta/misplaced data gets cleaned up.
    $pages = get_pages( $parsed_args );

    if ( ! empty( $pages ) ) {
        if ( $parsed_args['title_li'] ) {
            $output .= '<li class="pagenav">' . $parsed_args['title_li'] . '<ul>';
        }
        global $wp_query;
        if ( is_page() || is_attachment() || $wp_query->is_posts_page ) {
            $current_page = get_queried_object_id();
        } elseif ( is_singular() ) {
            $queried_object = get_queried_object();
            if ( is_post_type_hierarchical( $queried_object->post_type ) ) {
                $current_page = $queried_object->ID;
            }
        }

        $output .= walk_page_tree( $pages$parsed_args['depth']$current_page$parsed_args );

        if ( $parsed_args['title_li'] ) {
            $output .= '</ul></li>';
        }
    }

    
$data['post_name']   = wp_unique_post_slug( $data['post_name']$post['ID']$post['post_status']$post['post_type']$post['post_parent'] );
    }

    // Update the post.     edit_post();

    $wp_list_table = _get_list_table( 'WP_Posts_List_Table', array( 'screen' => $_POST['screen'] ) );

    $mode = 'excerpt' === $_POST['post_view'] ? 'excerpt' : 'list';

    $level = 0;
    if ( is_post_type_hierarchical( $wp_list_table->screen->post_type ) ) {
        $request_post = array( get_post( $_POST['post_ID'] ) );
        $parent       = $request_post[0]->post_parent;

        while ( $parent > 0 ) {
            $parent_post = get_post( $parent );
            $parent      = $parent_post->post_parent;
            $level++;
        }
    }

    $wp_list_table->display_rows( array( get_post( $_POST['post_ID'] ) )$level );

    

    $posts_per_page = apply_filters( 'edit_posts_per_page', $posts_per_page$post_type );

    $query = compact( 'post_type', 'post_status', 'perm', 'order', 'orderby', 'posts_per_page' );

    // Hierarchical types require special args.     if ( is_post_type_hierarchical( $post_type ) && empty( $orderby ) ) {
        $query['orderby']                = 'menu_order title';
        $query['order']                  = 'asc';
        $query['posts_per_page']         = -1;
        $query['posts_per_archive_page'] = -1;
        $query['fields']                 = 'id=>parent';
    }

    if ( ! empty( $q['show_sticky'] ) ) {
        $query['post__in'] = (array) get_option( 'sticky_posts' );
    }

    
if ( ! empty( $_REQUEST['mode'] ) ) {
            $mode = 'excerpt' === $_REQUEST['mode'] ? 'excerpt' : 'list';
            set_user_setting( 'posts_list_mode', $mode );
        } else {
            $mode = get_user_setting( 'posts_list_mode', 'list' );
        }

        // Is going to call wp().         $avail_post_stati = wp_edit_posts_query();

        $this->set_hierarchical_display(
            is_post_type_hierarchical( $this->screen->post_type )
            && 'menu_order title' === $wp_query->query['orderby']
        );

        $post_type = $this->screen->post_type;
        $per_page  = $this->get_items_per_page( 'edit_' . $post_type . '_per_page' );

        /** This filter is documented in wp-admin/includes/post.php */
        $per_page = apply_filters( 'edit_posts_per_page', $per_page$post_type );

        if ( $this->hierarchical_display ) {
            $total_items = $wp_query->post_count;
        }
$page = true;
                    }
                }

                if ( ! $post ) {
                    // For custom post types, we need to add on endpoints as well.                     foreach ( get_post_types( array( '_builtin' => false ) ) as $ptype ) {
                        if ( str_contains( $struct, "%$ptype%" ) ) {
                            $post = true;

                            // This is for page style attachment URLs.                             $page = is_post_type_hierarchical( $ptype );
                            break;
                        }
                    }
                }

                // If creating rules for a permalink, do all the endpoints like attachments etc.                 if ( $post ) {
                    // Create query and regex for trackback.                     $trackbackmatch = $match . $trackbackregex;
                    $trackbackquery = $trackbackindex . '?' . $query . '&tb=1';

                    
if ( is_array( $block->context['query']['author'] ) ) {
                $query['author__in'] = array_filter( array_map( 'intval', $block->context['query']['author'] ) );
            } elseif ( is_string( $block->context['query']['author'] ) ) {
                $query['author__in'] = array_filter( array_map( 'intval', explode( ',', $block->context['query']['author'] ) ) );
            } elseif ( is_int( $block->context['query']['author'] ) && $block->context['query']['author'] > 0 ) {
                $query['author'] = $block->context['query']['author'];
            }
        }
        if ( ! empty( $block->context['query']['search'] ) ) {
            $query['s'] = $block->context['query']['search'];
        }
        if ( ! empty( $block->context['query']['parents'] ) && is_post_type_hierarchical( $query['post_type'] ) ) {
            $query['post_parent__in'] = array_filter( array_map( 'intval', $block->context['query']['parents'] ) );
        }
    }

    /** * Filters the arguments which will be passed to `WP_Query` for the Query Loop Block. * * Anything to this filter should be compatible with the `WP_Query` API to form * the query context which will be passed down to the Query Loop Block's children. * This can help, for example, to include additional settings or meta queries not * directly supported by the core Query Loop Block, and extend its capabilities. * * Please note that this will only influence the query that will be rendered on the * front-end. The editor preview is not affected by this filter. Also, worth noting * that the editor preview uses the REST API, so, ideally, one should aim to provide * attributes which are also compatible with the REST API, in order to be able to * implement identical queries on both sides. * * @since 6.1.0 * * @param array $query Array containing parameters for `WP_Query` as parsed by the block context. * @param WP_Block $block Block instance. * @param int $page Current query's page. */
'format'             => '',
            'prev_text'          => '<span aria-label="' . esc_attr__( 'Previous page' ) . '">' . __( '&laquo;' ) . '</span>',
            'next_text'          => '<span aria-label="' . esc_attr__( 'Next page' ) . '">' . __( '&raquo;' ) . '</span>',
            /* translators: Hidden accessibility text. */
            'before_page_number' => '<span class="screen-reader-text">' . __( 'Page' ) . '</span> ',
            'total'              => $num_pages,
            'current'            => $pagenum,
        )
    );

    $db_fields = false;
    if ( is_post_type_hierarchical( $post_type_name ) ) {
        $db_fields = array(
            'parent' => 'post_parent',
            'id'     => 'ID',
        );
    }

    $walker = new Walker_Nav_Menu_Checklist( $db_fields );

    $current_tab = 'most-recent';

    if ( isset( $_REQUEST[ $tab_name ] ) && in_array( $_REQUEST[ $tab_name ], array( 'all', 'search' ), true ) ) {
        
$queried_object    = $wp_query->get_queried_object();
    $queried_object_id = (int) $wp_query->queried_object_id;

    $active_object               = '';
    $active_ancestor_item_ids    = array();
    $active_parent_item_ids      = array();
    $active_parent_object_ids    = array();
    $possible_taxonomy_ancestors = array();
    $possible_object_parents     = array();
    $home_page_id                = (int) get_option( 'page_for_posts' );

    if ( $wp_query->is_singular && ! empty( $queried_object->post_type ) && ! is_post_type_hierarchical( $queried_object->post_type ) ) {
        foreach ( (array) get_object_taxonomies( $queried_object->post_type ) as $taxonomy ) {
            if ( is_taxonomy_hierarchical( $taxonomy ) ) {
                $term_hierarchy = _get_term_hierarchy( $taxonomy );
                $terms          = wp_get_object_terms( $queried_object_id$taxonomy, array( 'fields' => 'ids' ) );
                if ( is_array( $terms ) ) {
                    $possible_object_parents = array_merge( $possible_object_parents$terms );
                    $term_to_ancestor        = array();
                    foreach ( (array) $term_hierarchy as $anc => $descs ) {
                        foreach ( (array) $descs as $desc ) {
                            $term_to_ancestor[ $desc ] = $anc;
                        }
                    }
Home | Imprint | This part of the site doesn't use cookies.