Forums

[resolved] registered user only link, displaying link from custom field (6 posts)

  1. vachi
    Member
    Posted 12 months ago #

    i have a link that is stored in videoembed custom field in my posts

    i want registered only users to see this link

    this is what i have right now

    $download =<a href="<?php $key="videoembed"; echo get_post_meta($post->ID, $key, true);?>">Download</a>;
    	<?php
               if (is_user_logged_in()){
                    echo $download;
                 }
               else {
                   echo '<a href="http://www.vitamovie.com/site/wp-register.php">Download - Please Register and Log In</a>';
                   };
        ?>

    but this displays in the page source

    $download =<a href="http://site.com/blah/blah.mp4">Download</a>;

    and you see
    $download =Download;

    the "Download" being the correct link, how do i get rid of the $download or what is the correct way of writing this

    tx in advance

  2. MichaelH
    moderator
    Posted 12 months ago #

    Some think like:

    <?php
    $key="videoembed";
    $dl= get_post_meta($post->ID, $key, true);
    $download ='<a href= "' . $dl . '">Download</a>';
    echo $download;
    ?>
  3. vachi
    Member
    Posted 12 months ago #

    tx allot

    i out it it like this

    <?php
               if (is_user_logged_in()){
                    $key="videoembed";
    $dl= get_post_meta($post->ID, $key, true);
    $download ='<a href= "' . $dl . '">Download</a>';
    echo $download;
                 }
               else {
                   echo '<a href="http://www.vitamovie.com/site/wp-register.php">Download - Please Register and Log In</a>';
                   };
        ?>
  4. MichaelH
    moderator
    Posted 12 months ago #

    Okay good so this will work:

    <?php
      if (is_user_logged_in()){
    echo '<a href= "' . get_post_meta($post->ID, 'videoembed', true) . '">Download</a>';
      }
       else {
       echo '<a href="http://www.vitamovie.com/site/wp-register.php">Download - Please Register and Log In</a>';
       };
     ?>
  5. weblogian
    Member
    Posted 11 months ago #

    Can you kindly tell me where to put the code above?

  6. Shane G
    Member
    Posted 1 month ago #

    Hi,

    You need to add this code in the post where you are adding the download link in the post.

    Thanks,

    Shane G.

Reply

You must log in to post.

About this Topic