• Resolved abalegno

    (@abalegno)


    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.

    // Extract the title

    if (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 description

    if (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 to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Insert metadata programmatically’ is closed to new replies.