Use the meta_query
argument of WP_Query
. For example, if your custom field name is “year” and you want to get the post with year=2013
:
<?php
$loop = new WP_Query( array( 'post_type' => 'Sport',
'posts_per_page' => 3,
'meta_query' => array( 'meta_key' => 'year_comm',
'meta_value' => '2013',
//Assuming you are using numeric value
//if not, delete the next line
'type' => 'NUMERIC'
) ) );
?>
Or use the custom field parameters:
<?php
$loop = new WP_Query( array( 'post_type' => 'Sport',
'posts_per_page' => 3,
'meta_key' => 'year_comm'
//Assuming you are using numeric value
//if not, use meta_value
'meta_value_num' => '2013'
) );
?>