WP_CLI::out PHP Method

out() public static method

back-compat
public static out ( $str )
    public static function out($str)
    {
        fwrite(STDOUT, $str);
    }

Usage Example

Example #1
0
 /**
  * Get a list of posts.
  *
  * @subcommand list
  * @synopsis [--<field>=<value>] [--ids]
  */
 public function _list($_, $assoc_args)
 {
     $query_args = array('posts_per_page' => -1);
     foreach ($assoc_args as $key => $value) {
         if (true === $value) {
             continue;
         }
         $query_args[$key] = $value;
     }
     if (isset($assoc_args['ids'])) {
         $query_args['fields'] = 'ids';
     }
     $query = new WP_Query($query_args);
     if (isset($assoc_args['ids'])) {
         WP_CLI::out(implode(' ', $query->posts));
     } else {
         $fields = array('ID', 'post_title', 'post_name', 'post_date');
         $table = new \cli\Table();
         $table->setHeaders($fields);
         foreach ($query->posts as $post) {
             $line = array();
             foreach ($fields as $field) {
                 $line[] = $post->{$field};
             }
             $table->addRow($line);
         }
         $table->display();
     }
 }
All Usage Examples Of WP_CLI::out