Overwrite YoastSEO meta-tags with another page's

I'm writing a custom Wordpress theme and for a specific page I need to overwrite its meta-tags (printed by YoastSEO) with the meta-tags of another page I already know the ID of. I cannot just change the original page meta-tags because the replacement changes based off a custom field in the page.

I've tried this, but apparently wp_head() is unaffected by the_post()...

    head
    ...
    ?php
    if (...)
    {
        $meta_page = new WP_Query([ 'page_id' = $meta_page_id ]);
        while ( $meta_page-have_posts() )
        {
            $meta_page-the_post();
            wp_head();
        }
        wp_reset_postdata();
    }
    else wp_head() ?
    ...
    /head

Hope it's clear enough; first question here.

Thanks in advance.

Topic meta-query plugin-wp-seo-yoast wp-query seo query Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.