Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Save post_parent in a custom post type

You could use the wp_insert_post_data filter instead, which gives you direct access to the post’s data.

function wpa_insert_post( $data , $postarr ){ 
    //do something with $data['post_parent']
    return $data;
}
add_filter( 'wp_insert_post_data' , 'wpa_insert_post' , '99', 2 );

UPDATE:

I added the following to your code and it’s working:

function wpa_insert_post( $data , $postarr ){ 
    //do something with $data['post_parent']
    $data['post_parent'] = intval($postarr['post_parent']);

    //update meta data
    update_post_meta($postarr['ID'], 'author', $postarr['author']);
    update_post_meta($postarr['ID'], 'price', $postarr['price']);

    return $data;
}
add_filter( 'wp_insert_post_data' , 'wpa_insert_post' , '99', 2 );

Related Posts:

  1. Query all posts where a meta key does not exist
  2. what is the correct way to compare dates in a WP query_posts meta_query
  3. Get post with multiple meta keys and value
  4. Admin Area Custom Type Search By Meta Fields Without Title & Content
  5. Echo all meta keys of a custom-post TYPE
  6. Post metadata deletes itself
  7. Detect meta value changes when post is updated (post_updated)
  8. Custom Post Type: Set post_title equal to a custom post type field
  9. I can’t set meta_key in my custom post type query
  10. Compare 3 custom fields and sort by oldest
  11. How can I include meta box content when searching?
  12. update a post meta from a single table cell TablePress
  13. Custom Meta Boxes – Nonce Issue – Move to trash issue
  14. Automatically adding meta data to posts or multiple query help
  15. Trigger “unsaved changes” dialog for custom post meta changes
  16. Conditionally Query Custom Post Types by Post Meta for Blog Home Page?
  17. Displaying custom posts only if custom meta box’s date is not expired
  18. Displaying Metabox value (custom post type taxonomy)
  19. How do I sort a custom post type admin column using two meta keys?
  20. How can I display my custom metaboxes on a custom post template?
  21. get_post_meta is returning image id
  22. Custom Post Type, Saving Multiple Checkboxes
  23. Create a random unique 6 digit number as custom field for custom post type
  24. Export entries and multiple custom field meta to .csv?
  25. how to interconnect custom post types?
  26. Metadata for a taxonomy – is there any WordPress way of doing this?
  27. orderby in custom WP Query does not work
  28. Insert post metadata for all posts in CPT at once if metadata no existent
  29. Display custom post type from dynamic custom field
  30. Populate dropdown from one custom post type inside another custom post type
  31. Notice: Undefined index: error and understanding wordpress
  32. Custom Post Types. Are there any disadvantages/advantages in using a plugin to develop them?
  33. Get posts between custom dates
  34. Deleting Custom Posts & Meta Data on Uninstall
  35. How do I create an archive page as a including metadata?
  36. A better way to add a meta box to custom post types
  37. Two Custom Post Types Many to Many Relationship
  38. how can I register a post_meta field in an existing CPT and then call it again with get_post_custom()?
  39. post meta parameter in post custom-post-type endpoint with restapi
  40. How do I set all of a particular post meta to a value within the custom post type I’m in?
  41. Update postmeta Parent when post_status child change
  42. Update database from Quick Edit according to Checkbox state of Custom Post Type
  43. Custom fields (wp_post_meta) vs Custom Table for large amount of data
  44. Storing a many to many post type relationship in post meta and keeping SQL ability for Joins
  45. Dynamic Custom Fields
  46. Show Custom Post Type meta boxes only on Page Edit
  47. Custom filter function not working with Custom post type
  48. Importing Data from a Non-WordPress database, into WP
  49. List Taxonomies: Don’t list taxonomy if it has no post – depending on custom post-meta?
  50. Can’t publish custom post type – “You are not allowed to edit this post.”
  51. Filter date from post meta when date is in string format
  52. Get only used meta_values
  53. Get $post->ID from a URL
  54. Displaying a div from an assigned meta_value when on a page
  55. Setting Post Title via Meta Data returns Auto-draft
  56. Values from meta-box not on $_POST
  57. Returning a custom content types with meta values
  58. Custom post type suddenly stoped working after WordPress 5 update
  59. How to show custom field on specific custom post type posts only when filled
  60. is_main_query() never called on WP 4.4
  61. How can I output WPAlchemy repeating fields meta values in my page template?
  62. Meta box data not saving
  63. Related posts meta_query CPT
  64. Meta box with front-end styling
  65. How can I get some of a posts meta data whilst it is still inserting?
  66. How to retrive Custom Post Type Meta Fields in Custom WP_Query
  67. Cannot Save MetaBox Data in Custom Post Type
  68. best way to use custom taxonomy, post type and meta in a job system
  69. Say I have a tech blog, how best would I store technical specs for a phone, if i use custom post types
  70. How to order custom posts by one of the custom fields value, ‘date’?
  71. Hide title field of selected post-types on edit pages
  72. WordPress CPT Taxonomy Dashboard Search – How to include taxonomy in search?
  73. Custom Post Type meta data getting deleted on bulk editing taxonomies
  74. How to create review point system for CPTs (many-to-many relationship)
  75. After inserting new post with wp_insert_post() the post is not visble to WP_Query, but the same WP_Query works for post inserted from wp-admin panel
  76. How can I write a function that would update any missing specific post metadata?
  77. SELECT custom post type and its meta in SQL
  78. How to keep custom post type related information
  79. Custom attachment function not working in v5.4.2?
  80. Can’t save meta box data in WordPress using custom post types
  81. How can I use a custom template to load custom post type posts based on a post_meta value
  82. How to properly get the wp_postmeta.meta_value of a custom post type in specifics?
  83. Custom Function to redirect singular post if specific meta field is empty
  84. Saving Child Terms on front end not setting parent
  85. Custom post type: “transition_post_status” action get title and other fields
  86. update a posts of other custom post type
  87. How do I extract the contents of a CPT’s custom field for all posts?
  88. Delete custom post type metadata without deleting the post in admin area
  89. Order by post meta value gets random results
  90. How can I get the $key / $value pairs of custom fields that were added via 3rd party plugins or themes?
  91. meta query always fails even if data is correct
  92. Display a post count from a custom metabox selection
  93. Rich Custom Field for Custom Post type not saving
  94. Custom post type submenu sorted by specific meta_key & meta_value
  95. Post AND page parameter for WP function
  96. How to display Author Profile based on Custom field value
  97. Automatically add custom taxonomy when meta value gets to a set number or beyond
  98. Display a list of posts whose meta field values are equal to the ID of the post being viewed?
  99. Check for custom field value in different post type than current one and do something
  100. I am having a problem with fetching product data in the Gutenberg block editor
Categories custom-post-types Tags custom-post-types, post-meta
Pageview confusion [closed]
What does WordPress mean by they have full rights to content [closed]

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress