Using WordPress ‘get_inline_data()’ PHP function

The get_inline_data() WordPress PHP function adds hidden fields with the data for use in the inline editor for posts and pages.

Usage

get_inline_data( $post );

Custom example:

Input:

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

Output:

<!-- Hidden fields with post data for the inline editor -->

Parameters

  • $post WP_Post (Required): Post object to be used with the inline editor.

More information

See WordPress Developer Resources: get_inline_data

Examples

Add Inline Editor Data for a Specific Post

Retrieve a specific post by ID and add the inline editor data for it.

$post_id = 42;
$post = get_post( $post_id );
get_inline_data( $post );

Add Inline Editor Data for the Current Post in The Loop

In a WordPress loop, add the inline editor data for each post.

while ( have_posts() ) {
  the_post();
  get_inline_data( $post );
}

Adding Inline Editor Data to a Custom Query

For a custom query of posts, add the inline editor data for each post.

$args = array(
  'post_type' => 'post',
  'posts_per_page' => 10,
);

$query = new WP_Query( $args );

while ( $query->have_posts() ) {
  $query->the_post();
  get_inline_data( $post );
}

Add Inline Editor Data for Posts with a Specific Category

Retrieve posts with a specific category and add the inline editor data for each post.

$category = 'news';
$args = array(
  'category_name' => $category,
  'posts_per_page' => 5,
);

$query = new WP_Query( $args );

while ( $query->have_posts() ) {
  $query->the_post();
  get_inline_data( $post );
}

Add Inline Editor Data for Posts with a Custom Post Type

Retrieve posts with a custom post type and add the inline editor data for each post.

$args = array(
  'post_type' => 'my_custom_post_type',
  'posts_per_page' => 10,
);

$query = new WP_Query( $args );

while ( $query->have_posts() ) {
  $query->the_post();
  get_inline_data( $post );
}