php - 如何在 WordPress 上获取帖子的自定义文件?
问题描述
此方法get_posts()
返回所有字段!
但我需要获取自定义字段,例如我只想获取id
和title
它们的类别名称。
解决方案
我认为通过传递参数你可以得到你想要的。
$args = array(
'numberposts' => -1, // -1 is for all
'post_type' => 'movie', // or 'post', 'page'
'orderby' => 'title', // or 'date', 'rand'
'order' => 'ASC', // or 'DESC'
);
// Get the posts
$posts = get_posts($args);
// If there are posts
if($posts){
// Loop the posts
foreach ($posts as $post){
var_dump($mypost->ID); // you have ID here
}
}