Ready to get started?Download WordPress


Call a custom field in the loop (7 posts)

  1. Marcomail
    Posted 8 years ago #

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

  2. schulte
    Posted 8 years ago #

  3. Marcomail
    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(); ?>
    <img src="/wp-content/themes/tb/images/img.gif"> <a href="<?php the_permalink() ?>" rel="bookmark" target="_blank"><?php the_title(); ?></a>
    <?php endwhile; ?>

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

  4. schulte
    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
    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
    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