2

I would like this query to only show the posts if it contains and text that comes from geodir_special_offers echo

<?php

global $post;

$args = array( 

 'posts_per_page' => 4 , 'post_type' => 'gd_arts',);

$lastposts = get_posts( $args ); foreach ( $lastposts as $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 am quite new to WP queries so bear with me.

Sorry in advance if it is not structured 100%.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189

1 Answers1

0

Try this!It checks if the special offers is set before echoing out the content. Hope that's what you were looking for.

<?php

global $post;

$args = array( 

 'posts_per_page' => 4 , 'post_type' => 'gd_arts',);

$lastposts = get_posts( $args ); 
foreach ( $lastposts as $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(); 
?>