lundi 2 mars 2015

How to get latest post value if first post is empty in wordpress


I am working on wordpress custom field. I am facing problem to get custom field value if latest post custom field value is empty then display second latest post or from other post custom field value. My custom field is video if latest post have no video then show 2 latest post video value.I dont know how to get 2latest post custom field value.


Here is my code:-



<?php

$page_num = $paged;
if ($pagenum='') $pagenum =1;
while (have_posts()) : the_post();
$args = array(
'posts_per_page' => 1,
'paged' => $page_num,
'order' => 'DESC',
'orderby' => 'post_date',
'offset'=> 0,
'meta_query' => array(
array(
'key' => 'video'
)
)

);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
$specials = get_post_meta( $post->ID,'video');
foreach( $specials as $special): setup_postdata($special);

echo '<iframe width="699" height="269" src="http://ift.tt/Ajy3Fh'.$special.'?controls=1&showinfo=0&rel=0" allowfullscreen></iframe>';

endforeach;
endwhile;
wp_reset_query();
?>


kindly advice me any solution.





Aucun commentaire:

Enregistrer un commentaire