使用meta_query
的参数WP_Query
. 例如,如果您的自定义字段名为“year”,并且您希望使用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\'
) ) );
?>
或使用自定义字段参数:
<?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\'
) );
?>