Title: Insert metadata programmatically
Last modified: August 22, 2024

---

# Insert metadata programmatically

 *  Resolved [abalegno](https://wordpress.org/support/users/abalegno/)
 * (@abalegno)
 * [1 year, 9 months ago](https://wordpress.org/support/topic/insert-metadata-programmatically/)
 * Hello, I am programming a function that extracts meta description and meta keywords
   from a specific page, I am trying to insert them into the corresponding post:
   `
   update_post_meta($post_id, '_aioseop_description', $meta_description);update_post_meta(
   $post_id, '_aioseop_keywords', $meta_keywords);
 * I don’t know if I’m using the correct constants (_aioseop_description and _aioseop_keywords)
   or not, but I can’t insert what I need into AIOSEO, nor do I have any kind of
   error.
   I would appreciate any help on this, and I’m attaching my full code, just
   in case.
 *     ```wp-block-code
       // Extract the titleif (preg_match('/<title>(.*?)<\/title>/i', $page_content, $matches)) {$page_title = $matches[1];error_log('Page title found: ' . $page_title);} else {error_log('Page title not found.');}// Extract meta descriptionif (preg_match('/<meta name="description" content="([^"]*)"/i', $page_content, $matches)) {$meta_description = $matches[1];update_post_meta($post_id, '_aioseop_description', $meta_description);error_log('Meta description updated: ' . $meta_description);} else {error_log('Meta description not found.');}// Extract meta keywords (if available)if (preg_match('/<meta name="keywords" content="([^"]*)"/i', $page_content, $matches)) {$meta_keywords = $matches[1];update_post_meta($post_id, '_aioseop_keywords', $meta_keywords);error_log('Meta keywords updated: ' . $meta_keywords);} else {error_log('Meta keywords not found.');}$post = array('ID' => $post_id,'post_title' => $page_title,);wp_update_post($post);
       ```
   
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Finsert-metadata-programmatically%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [dgmdonna](https://wordpress.org/support/users/dgmdonna/)
 * (@dgmdonna)
 * [1 year, 9 months ago](https://wordpress.org/support/topic/insert-metadata-programmatically/#post-17969873)
 * I have been having the same problem for a week, is there any solution?
 *  Plugin Support [MM Aurangajeb](https://wordpress.org/support/users/aurangajeb/)
 * (@aurangajeb)
 * [1 year, 9 months ago](https://wordpress.org/support/topic/insert-metadata-programmatically/#post-17972377)
 * Hi [@abalegno](https://wordpress.org/support/users/abalegno/),
 * Thanks for reaching out!
 * I found that you have already contacted us through our site’s [Contact Us](https://aioseo.com/contact/)
   form. We will continue the conversation there.
 * Hey [@dgmdonna](https://wordpress.org/support/users/dgmdonna/), if you need support,
   then per the forum guidelines, please start your own topic. [https://wordpress.org/support/forum-user-guide/faq/#i-have-the-same-problem-can-i-just-reply-to-someone-elses-post-with-me-too](https://wordpress.org/support/forum-user-guide/faq/#i-have-the-same-problem-can-i-just-reply-to-someone-elses-post-with-me-too)
 * We may also need to ask for more details in your specific case.
 * Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Insert metadata programmatically’ is closed to new replies.

 * ![](https://ps.w.org/all-in-one-seo-pack/assets/icon.svg?rev=2443290)
 * [All in One SEO – Powerful SEO Plugin to Boost SEO Rankings & Increase Traffic](https://wordpress.org/plugins/all-in-one-seo-pack/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/all-in-one-seo-pack/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/all-in-one-seo-pack/)
 * [Active Topics](https://wordpress.org/support/plugin/all-in-one-seo-pack/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/all-in-one-seo-pack/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/all-in-one-seo-pack/reviews/)

## Tags

 * [description](https://wordpress.org/support/topic-tag/description/)
 * [keywords](https://wordpress.org/support/topic-tag/keywords/)
 * [meta keywords](https://wordpress.org/support/topic-tag/meta-keywords/)

 * 2 replies
 * 3 participants
 * Last reply from: [MM Aurangajeb](https://wordpress.org/support/users/aurangajeb/)
 * Last activity: [1 year, 9 months ago](https://wordpress.org/support/topic/insert-metadata-programmatically/#post-17972377)
 * Status: resolved