get all post by custom field wordpress

Posted: January 12, 2015 in All Category, WordPress

<?php

// args
$args = array(
'numberposts' => -1,
'post_type' => 'estate_project',
'meta_key' => 'project_city',
'meta_value' => '1043'
);

// get results
$the_query = new WP_Query( $args );

// The Loop
?>
<?php if( $the_query->have_posts() ): ?>
<ul>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>

Advertisements

Comments are closed.