[wp-hackers] Conditional statement inside custom query

mailapera mailapera at gmail.com
Tue Aug 3 13:17:40 UTC 2010


I am trying to call a custom field into a custom query array, however the
custom field itself must be filtered by a conditional statement to output
the correct value. Here the code

<?php if ($related_query->have_posts())
:
    $postsArray = array();
    while ($related_query->have_posts()) : $related_query->the_post();
        $gal = get_post_meta($post->ID, 'metakey1', true);
        $gal = apply_filters('the_content', $gal );
        $fruit = get_post_meta($post->ID, 'metakey2', true);

        if ($fruit=="1") {
        Apples
        } elseif($fruit=="2") {
        Cherries
        }

        $postsArray[] = '<div
style="display:block;float:left;margin-left:10px;"><a
href="'.get_permalink().'" rel="bookmark" id="inline"><span
id="relimg">'.$gal.'</span></a><br /><span
style="font-size:70%;">'.get_the_title().'<br />'.get_post_meta($post->ID,
'type', true).'<br />'.$fruit.'</span></div><!-- ('.get_the_score().')-->';
    endwhile;

echo implode(' '."\n",$postsArray); // print out a list of the related
items, separated by commas
else:?>


I have no ide what the correct syntax is, or if this can even be done.
Thanks for any help


More information about the wp-hackers mailing list