i have external link stored in a variable $extlink
which is generated based on different selections in the post.
how do i set the permalink to be this $extlink
so that when i click on the post it takes me to the link via program/code
<?php while (have_posts()) : the_post(); ?>
<div class="bookindex">
<?php the_title();?>
<?php
$ext1 = get_field('bookzone');
$extlink="http://".$ext1.".com";
add_filter( 'post_link', 'external_permalink', 10, 2 );
function external_permalink( $link, $post )
{
$meta = get_post_meta( $post->ID, $extlink , TRUE );
$url = esc_url( filter_var( $meta, FILTER_VALIDATE_URL ) );
return $url ? $url : $link;
}
?>
</div>
<?php endwhile; ?>
add_filter()
and its associated callback function in The Loop. They should be separate. Also, do you want to filter every URL, or only specific ones?