• Resolved nnproducts

    (@nnproducts)


    Trying to insert the URL for any given organization into a list of search results. The following inserts the post metadata for the custom field ‘link’ but inserts the first item’s URL for all subsequent items in the results. Obviously, I need the URL for each individual organization. Not sure what I am missing.

    <!-- Loop -->
     <?php 
    	$link = get_post_meta(get_the_ID(), 'link', TRUE);
            if ( have_posts() ) { 
                while ( have_posts() ) : the_post(); ?>
    		<p><a href="<?php echo $link; ?>"><?php the_title(); ?></a></p>
    		<?php
                    get_template_part( 'parts/content', get_post_format() );
                endwhile;
    	} 
            else { ?>
            <div class="no-results"><p><?php _e('No posts found.', 'vega'); ?></p></div>
            <?php } ?>
    <!-- /Loop -->

    Any assistance appreciated.

    Thanks!

    • This topic was modified 4 years, 5 months ago by nnproducts.
Viewing 2 replies - 1 through 2 (of 2 total)
  • You should probably do this inside the loop, i. e.:

    <?php 
    	if ( have_posts() ) { 
    		while ( have_posts() ) : the_post();
    			$link = get_post_meta(get_the_ID(), 'link', TRUE);
    ?>
    			<p><a href="<?php echo $link; ?>"><?php the_title(); ?></a></p>
    …
    …
    Thread Starter nnproducts

    (@nnproducts)

    @10010110,

    I tried that, but, I think that I must have had the syntax wrong. Working now!

    Thank you for the quick reply!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Loop Issue’ is closed to new replies.