質問

Typically I go to the dashboard to set a pages parent attribute. Suppose I am dynamically creating a page so it is not available to edit through the dashboard, is there a way to programmatically set the parent attribute?

Thanks

役に立ちましたか?

解決

You can look into the wp_insert_post() function. It takes a $post array, and you can set the parent ID. here's the link: http://codex.wordpress.org/Function_Reference/wp_insert_post

here's an example:

// Create post object
$my_post = array(
  'post_title'    => 'My post',
  'post_content'  => 'This is my post.',
  'post_status'   => 'publish',
  'post_type'     => 'page',
  'post_author'   => 1,
  'post_parent'   => [ <post ID> ], // Sets the parent of the new post, if any. Default 0.
  'post_category' => array(8,39)
);

// Insert the post into the database
wp_insert_post( $my_post );

I hope it helps! --updated with example

他のヒント

Check wp_insert_post -- http://codex.wordpress.org/Function_Reference/wp_insert_post

You can set post parent via the post_parent argument.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top