Search code examples
wordpresshyperlinkacfpro

Get meta from podcast episode into wordpress template


Is there a way to get the Podcast Name, Episode Title, and Date through a link inserted in a wordpress post? I'm using ACF plugin where the user may insert a podcast link.

Like what happens when I paste a link in WhatsApp, and an information with appears containing even an image or a logo from the website pasted.

Thank you. AMP.


Solution

  • Yes!

    Option 1

    You could hook into the save_post hook, get the url that has been supplied, grab the data from that url with either curl / file_get_contents / whatever and then save the data as post meta for that post.

    On the frontend, you can grab the saved data from the post meta.

    Option 2

    You could also grab the data on the frontend. Either with php in wordpress, or on the client side with js (e.g. axios or fetch). You get the acf link and pass it to e.g. window.WP_VARS, for your clientside code to use it. I e.g. use this to pass generic vars to my clientside code:

      wp_register_script('mainjs', get_template_directory_uri() . '/js/main.js', array(), REL_VERSION, true);
      wp_localize_script('mainjs', 'WP_VARS', $generic_vars);
      wp_enqueue_script('mainjs');
    

    The advantage of this is that you don't have to store and grab this data from your database. Make sure that the fetch is non blocking, so do it on page ready.