Your code cannot work. At first, your endwhile;
and endif
statements are inside the string. They will be printed and not executed. The correct formatted code should look like this
$hotfoodpresent = get_posts( array('post_type' => 'st_notice', 'posts_per_page' =>-1) );
if ( $hotfoodpresent )
echo '<a class="lbp-inline-link-1 cboxElement" href="#"></a>
<div style="display: none;">
<div id="lbp-inline-href-1" style="padding:10px; background: #fff;">';
if ( have_posts() ): while ( have_posts() ): the_post();
wp_redirect( get_permalink() );
endwhile;
echo ' </div>';
echo '</div>';
endif;
But I still wonder what this code block should do
if ( have_posts() ): while ( have_posts() ): the_post();
wp_redirect( get_permalink() );
endwhile;
After wp_redirect()
you have to exit the code with exit()
or die()
. But before you use wp_redirect()
, you cannot print anything. This will result in a Headers already send
error.
wp_redirect()
do not print anything to the screen. There is no other code that will output anything. So what do you want to see if the lightbox open?
Maybe try printf( '<a href="https://wordpress.stackexchange.com/questions/99038/%s">Redirect</a>', get_permalink() );
instead of wp_redirect()
und you will get a link with the text ‘Redirect’.