首页 > 解决方案 > 如何在 WordPress 上获取帖子的自定义文件?

问题描述

此方法get_posts()返回所有字段!

但我需要获取自定义字段,例如我只想获取idtitle它们的类别名称。

标签: phpwordpress

解决方案


我认为通过传递参数你可以得到你想要的。

    $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
      }
    }

推荐阅读