Link title to external link instead of permalink

I’m trying to get the same effect as the plugin Pages Link To where the title of the post is linked to an external link. The reason I don’t want to use the plugin is the link is generated dynamically when the post is saved, but I’m unable to update the the permalink of the post with the external link.

Below is my code in functions.php:

function savepost( $post_id ) {
    if( $_POST['post_type'] == 'books' ){
    $genre = strip_tags(get_field('genre'));
    $author = strip_tags(get_field('author'));
    $extlink = "http://www.".$genre."/".$author.".com";

    update_post_meta( $post_id, 'post_link', $extlink);
}
}
add_action( 'save_post', 'savepost' );

Read more here: Link title to external link instead of permalink

Leave a Reply

Your email address will not be published. Required fields are marked *