sort a custom field base on the date or anything

Multiline is not an array (rant) You need to use standard dates for this to work DD/MM/YYYY (first row) Use the PHP function usort() to sort the fields Use strtotime() to convert that date to a timestamp and date_i18n() to output it If you need an actual example, change the date formats to what I’ve … Read more

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