Retrieve IDs from custom field, count and display results differently according to count

I answer to myself, since this code is working better (previous had an issue) and also I removed a useless “for”: echo ‘<ul class=”related-content”>’; $count = 0; foreach(get_field(‘related_content’) as $post_object) : $count++; if ($count > 0 && $count < 4 ) { printf(‘<li class=”large”><a target=”_blank” title=”‘.get_the_title($post_object->ID).'” href=”‘.get_permalink($post_object->ID).'”><span style=”display: block” title=”‘.get_the_title($post_object->ID).'”>’.get_the_post_thumbnail($post_object->ID, ‘small’).'</span><span class=”thumb-title”>’.get_the_title($post_object->ID).'</span></a></li>’); } elseif ($count … Read more

display loop only if a post meta data exist

If you want to avoid preprocessing the data, this will work (though it’s definitely the quick and dirty method): <?php while (have_posts()) : the_post(); ?> <?php $data = get_post_meta( $post->ID, ‘key’, true ); ?> <?php if( $data != ” ) : ?> <!– info –> <?php endif; ?> <?php endwhile; ?> Otherwise (and this is … Read more

How to check if custom field exists in this widget query

I can’t test it now, but the following should work… query_posts(‘post_type=sponsors&meta_key=_vof_sponsor_level&meta_value=Gold’); if (have_posts()) : echo “<div class=”imageshadow sponsorwidgetslides”>”; while (have_posts()) : the_post(); if ( get_post_meta($post->ID, ‘url’, true) ) { ?> <a href=”https://wordpress.stackexchange.com/questions/39982/<?php echo get_post_meta($post->ID,”url’,true); ?>”><?php the_post_thumbnail(‘sponsorwidget’);?></a> <?php } else { the_post_thumbnail(‘sponsorwidget’); } endwhile; echo “</div><!–/.imageshadow–>”; echo “<a class=”widgetlink” href=””; bloginfo(“url’); echo “/sponsors’>View all Sponsors &raquo;</a>”; … Read more

How to query posts that have certain post meta keys, and sort by meta key and/or value

how about array_reverse() http://php.net/manual/en/function.array-reverse.php there are a bunch of array manipulation functions at php.net. i’m always there looking something up. also sort() might be useful EDIT based on your comments: sort($album); print_r($album); should return: Array ( [0] => 001,Get Rich Or Die Tryin [1] => 002,Curtis [2] => 003,The Massacre [3] => 004,Before I Self … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)