Forums

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

  1. vachi
    Member
    Posted 3 years 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
    Volunteer
    Posted 3 years 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 3 years 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
    Volunteer
    Posted 3 years 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 3 years ago #

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

  6. Shane G
    Member
    Posted 2 years ago #

    Hi,

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

    Thanks,

    Shane G.

Topic Closed

This topic has been closed to new replies.

About this Topic