php - Wordpress query to only include posts that have certain content -


i query show posts if contains , text comes geodir_special_offers echo

<?php  global $post;  $args = array(    'posts_per_page' => 4 , 'post_type' => 'gd_arts',);  $lastposts = get_posts( $args ); foreach ( $lastposts $post ) : setup_postdata( $post ); ?>  <h2><a href="<?php the_permalink(); ?>"> <?php the_title(); ?> </a></h2>  <?php if ( has_post_thumbnail() ) {              the_post_thumbnail(array(486,226));         } ?> <php echo $post->geodir_special_offers; ?>  <?php endforeach;  wp_reset_postdata();  ?> 

i quite new wp queries bare me.

sorry in advance if not structured 100%.

cheers

shaun

try this!it checks if special offers set before echoing out content. hope that's looking for.

<?php  global $post;  $args = array(    'posts_per_page' => 4 , 'post_type' => 'gd_arts',);  $lastposts = get_posts( $args );  foreach ( $lastposts $post ) {?> <?php if(strlen ($post->geodir_special_offers) > 5){ ?> <h2><a href="<?php the_permalink(); ?>"> <?php the_title(); ?> </a></h2>  <?php if ( has_post_thumbnail() ) {              the_post_thumbnail(array(486,226));         }       } } wp_reset_postdata();  ?> 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -