• Resolved sweetheatmn

    (@sweetheatmn)


    To integrate with our plugin, we need to programmatically set the meta description for posts

    I tried

    update_post_meta($post_id, '_aioseo_description', $custom_description);

    The custom field was created and the value was set in it but AIOSEO is not reading from it

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Shivam Tyagi

    (@shivamtyagi)

    Hi @sweetheatmn,

    Thanks for reaching out!

    I understand you’re trying to programmatically set the meta description for posts. However, I’d like to clarify that All in One SEO stores its data in custom tables (e.g., the wp_aioseo_posts table for post-related data), not in the postmeta table.

    The _aioseo_description and other related fields you’re seeing in the postmeta table are actually duplicates created for compatibility purposes with plugins like WPML. These fields are not directly used by AIOSEO to retrieve or display SEO data.

    If you only need to set the meta description, you can use the aioseo_description filter to dynamically set it.

    Here’s an example code snippet you can use:

    add_filter( 'aioseo_description', 'aioseo_set_custom_meta_description' );
    function aioseo_set_custom_meta_description( $description ) {
    // Check if you're on the desired post.
    if ( is_singular() && get_the_ID() === 123 ) { // Replace 123 with the ID of your post.
    return "Your custom meta description here.";
    }
    return $description;
    }

    Let me know if you have further questions or if there’s anything else I can assist you with. I’m happy to help!

    Plugin Author arnaudbroes

    (@arnaudbroes)

    Hey @sweetheatmn,

    The approach above of my colleague Shivam is viable, but I just wanted to point out we also have another filter hook you can use that triggers when the post data is saved to the DB, so you can filter it before it gets stored.

    The aioseo_save_post hook triggers on post save and has two arguments. The first one is the $data that will be saved (including the title/description), the second is the AIOSEO Post model instance that holds the data that is currently already saved in the DB (you probably don’t need this one).

    If you have any questions, let us know!

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.