Using WordPress ‘page_attributes_meta_box()’ PHP function

The page_attributes_meta_box() WordPress PHP function displays page attributes form fields.

Usage

page_attributes_meta_box( $post );

Custom example:

Input:

$post = get_post(42); // Get post with ID 42
page_attributes_meta_box($post);

Output:
Displays the page attributes form fields for the post with ID 42.

Parameters

  • $post (WP_Post): Required. The current post object.

More information

See WordPress Developer Resources: page_attributes_meta_box

Examples

Display Page Attributes for a Specific Post

This example shows how to display the page attributes form fields for a specific post by passing the post object to the page_attributes_meta_box() function.

$post_id = 42; // Set the post ID
$post = get_post($post_id); // Get the post object
page_attributes_meta_box($post); // Display the page attributes

Display Page Attributes for the Current Post in the Loop

This example demonstrates how to display the page attributes form fields for the current post in the loop.

if ( have_posts() ) {
    while ( have_posts() ) {
        the_post();
        page_attributes_meta_box( $post );
    }
}

Display Page Attributes for a Post Using a Custom Query

This example shows how to display the page attributes form fields for a post using a custom query.

$args = array(
    'post_type' => 'page',
    'posts_per_page' => 1,
);
$query = new WP_Query($args);

if ($query->have_posts()) {
    while ($query->have_posts()) {
        $query->the_post();
        page_attributes_meta_box($post);
    }
}
wp_reset_postdata();

Display Page Attributes for All Pages

This example demonstrates how to display the page attributes form fields for all pages.

$args = array(
    'post_type' => 'page',
    'posts_per_page' => -1,
);
$query = new WP_Query($args);

if ($query->have_posts()) {
    while ($query->have_posts()) {
        $query->the_post();
        page_attributes_meta_box($post);
    }
}
wp_reset_postdata();

Display Page Attributes for Posts with a Specific Template

This example shows how to display the page attributes form fields for posts with a specific template.

$args = array(
    'post_type' => 'page',
    'meta_key' => '_wp_page_template',
    'meta_value' => 'your-template.php',
);
$query = new WP_Query($args);

if ($query->have_posts()) {
    while ($query->have_posts()) {
        $query->the_post();
        page_attributes_meta_box($post);
    }
}
wp_reset_postdata();