• Resolved Tyssen

    (@tyssen)


    I’ve got a page which uses this to insert a series of items into the body of the content (using exec-php plugin):

    <ul>
    <?php $my_query = new WP_Query('cat=XX');
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
    	<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endwhile; ?>
    </ul>

    That works fine except that now I want to replace the_permalink with a URL entered into a custom field, and if I do this:

    <ul>
    <?php $my_query = new WP_Query('cat=XX');
      while ($my_query->have_posts()) : $my_query->the_post();
    	$link = get_post_meta($post->ID, 'site-url', true); ?>
    	<li><a href="http://<?php echo $link; ?>"><?php the_title(); ?></a></li>
    <?php endwhile; ?>
    </ul>

    the link comes out blank.

    So, is it not possible to use custom fields in this manner, ie, inside a custom loop inside a normal WP loop?

Viewing 6 replies - 16 through 21 (of 21 total)
Viewing 6 replies - 16 through 21 (of 21 total)

The topic ‘Do custom fields work inside a WP_Query loop inside a page?’ is closed to new replies.