WordPress.org

Ready to get started?Download WordPress

Forums

Call a custom field in the loop (7 posts)

  1. Marcomail
    Member
    Posted 8 years ago #

    I have a link in the custom field "syndication_permalink", how can i call it in my loop ?

  2. schulte
    Member
    Posted 8 years ago #

  3. Marcomail
    Member
    Posted 8 years ago #

    Yes, i have already read it, but i don't understand :(

    this is my loop:

    <?php $my_query = new WP_Query('cat=6&showposts=8'); ?>
    <ul class="friendgallerieslist">
    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <li>
    <img src="/wp-content/themes/tb/images/img.gif"> <a href="<?php the_permalink() ?>" rel="bookmark" target="_blank"><?php the_title(); ?></a>
    </li>
    <?php endwhile; ?>

    i would call the custom link near the title of my post...what i do now ?

  4. schulte
    Member
    Posted 8 years ago #

    Stick this somewhere in there and see if it grabs the link you're seeking:

    <?php get_post_custom_values('syndication_permalink'); ?>

  5. Marcomail
    Member
    Posted 8 years ago #

    Schulte i ahve tried your tricks but it doesn't work....i have solved with this:

    <?php echo post_custom('syndication_permalink'); ?>

    Is it possible use a conditional tag for see if the custom field exist ?

  6. schulte
    Member
    Posted 8 years ago #

    Didn't know about post_custom. Learn something everyday...I don't think it's in the Codex...ouch.

    I don't see why you couldn't check for the presence of the field or at the very least the field length...

    is_post_custom would be cool...

  7. Samuel Wood (Otto)
    Tech Ninja
    Posted 8 years ago #

    Here you go.

    $custom = get_post_custom_values('syndication_permalink');
    if (count($custom) != 0)
    {
    // do your thing
    echo $custom[0];
    // maybe do more things
    }

Topic Closed

This topic has been closed to new replies.

About this Topic