Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

madsrh123 on "$_Session inside while"

$
0
0

I need to bring the $i to my target page.
This gives me a list of track titles with a permalink, but on my target page I only get the last $i.

<?php $args = array( 'post_type' => 'album' );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
$i = 1;

	the_title();

	// Gets track ID foreach track
	while ($i > 0) {
 	   $track = get_field ('track'.$i);

 	$permalink = get_permalink( $id );
 	session_start(); // STARTS VARIABLE TO SEND I TO NEXT PAGE
           $_SESSION['variable_name'] = $i;

 	   if ($track != '') {
		echo '<br><a href="' . $permalink . '"><strong>' . $i . ' <strong>' . get_field ('track'.$i) . '</a>';
		$i++;
	    }
	    else {
	        $i = 0;
	    }
	}

endwhile; ?>

And the target page contains:

session_start();
echo $_SESSION['variable_name'];

Viewing all articles
Browse latest Browse all 8245

Trending Articles