How to display the Patreon post's URL in a WordPress post

I want to double-check that my logic is sound before I code this in with my child theme editor - it seems fairly straightforward. I’d like guidance and any suggestions - I’m learning PHP and know that I could have made some mistakes. :slight_smile:

Edit: Inspiration came from this post from 2021.

For a post sync’ed to WordPress from Patreon: display the URL for the original Patreon post as a link within the WordPress post. My client wants to make it easy for people to get back to Patreon from WordPress (and vice-versa).

I have created a child theme for my customizations. I will update the theme to call the get_post_meta function to retrieve the patreon-post-url custom field. This custom field is populated for a post when it is synchronized with the WordPress plugin. (I am not sure if this field is from the free WordPress plugin or the Patron Pro plugin. I use Pro.)

Edit the functions.php file to retrieve the value of the custom field when the page loads.

$patreon_url_field = get_post_meta( get_the_ID(), 'patreon-post-url', true );
$full_patreon_post_url = '<MY_CLIENTS_PAGE>/posts' . $patreon_url_field;
echo $full_patreon_post_url;

And I will add this to the single blog page template so that the URL shows up there.
<a href="<?php echo $full_patreon_post_url; ?>">Posted on Patreon</a>

The url format should be

for an individual post. So you will likely need to make the format fit that. with the post id also works.