Title: Using a cookie within the Loop
Last modified: August 20, 2016

---

# Using a cookie within the Loop

 *  [teahou](https://wordpress.org/support/users/teahou/)
 * (@teahou)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/using-a-cookie-within-the-loop/)
 * Hi. I am working on a site using the Prosto theme. It is a site that sells subscriptions
   to videos. Here is a link: [http://www.vjortho.com](http://www.vjortho.com)
 * I need to add a piece of code to the loop that will send a paid subscriber directly
   to the full length video if he/she has already subscribed to that video, otherwise
   they go to the regular “synopsis’ page
 * The “synopsis” page is here:
    [http://www.vjortho.com/2010/12/computer-assisted-subtalar-arthrodesis/](http://www.vjortho.com/2010/12/computer-assisted-subtalar-arthrodesis/)
   The “full length” page is here: [https://www.vjortho.com/videos/video.cfm?vid=1033](https://www.vjortho.com/videos/video.cfm?vid=1033)
 * I wrote this code:
 *     ```
       // Custom funcion to forward user directly to full video if is a registered subscriber to that video
   
       $videoid = get_post_meta($post->ID, 'Catalog Number', true);
   
       function Streaming($videoid)
       {
       	if(isset($_COOKIE['subscription']))
       	{
       		if (in_array("streaming", $_COOKIE['subscription']) || (in_array($videoid, $_COOKIE['subscription']))
       		{
       			return true;
       		}
       		else
       		{
       			return false;
       		}
       	}
       }	
   
       $validUser = Streaming($videoid);
   
       $vidlink = "https://www.vjortho.com/videos/video.cfm?vid=" . $videoid;
   
       // END forwarding function
       ```
   
 * … and added a call to it here (in bold):
 *     ```
       <div id="post-<?php the_ID(); ?>" <?php post_class($portfolioclass); ?>><?php if ( !is_single()  ) {if ($portlayout != '2' ) {?><h5 class="entry-title"><a href="<?php if($lightbox !='' && $link !='') { echo $link;} <strong>elseif($validUser == true) {echo $vidlink; }</strong> else { the_permalink(); } ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'prosto' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php prosto_the_title_limited(18); ?></a></h5><?php } ?>
       ```
   
 * but when I saved it to the loop, the site broke (nothing would display). So, 
   if any one has an idea as to where I went wrong, please drop me a hint. ps: I
   know the cookie is set and working, it is just this side of it that is giving
   me fits).

The topic ‘Using a cookie within the Loop’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [teahou](https://wordpress.org/support/users/teahou/)
 * Last activity: [14 years, 9 months ago](https://wordpress.org/support/topic/using-a-cookie-within-the-loop/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
