V
V
Vladimir Kulikov2020-05-25 15:30:06
WordPress
Vladimir Kulikov, 2020-05-25 15:30:06

Why can't I get the author's id from the get_post() array?

Hello, this design does not cause an error.

echo '<pre>';
    $post_info = get_post();
    var_dump($post_info);
    echo '</pre>';


And if you try to get the author's id, then nothing works.
echo '<pre>';
    $post_info = get_post();
    var_dump($post_info["post_author"]);
    echo '</pre>';


var_dump get_post();
object(WP_Post)#10012 (24) {
  ["ID"]=>
  int(802)
  ["post_author"]=>
  string(1) "1"
  ["post_date"]=>
  string(19) "2020-05-25 15:14:45"
  ["post_date_gmt"]=>
  string(19) "2020-05-25 12:14:45"
  ["post_content"]=>
  string(0) ""
  ["post_title"]=>
  string(2) "01"
  ["post_excerpt"]=>
  string(0) ""
  ["post_status"]=>
  string(7) "publish"
  ["comment_status"]=>
  string(6) "closed"
  ["ping_status"]=>
  string(6) "closed"
  ["post_password"]=>
  string(0) ""
  ["post_name"]=>
  string(2) "02"
  ["to_ping"]=>
  string(0) ""
  ["pinged"]=>
  string(0) ""
  ["post_modified"]=>
  string(19) "2020-05-25 15:14:45"
  ["post_modified_gmt"]=>
  string(19) "2020-05-25 12:14:45"
  ["post_content_filtered"]=>
  string(0) ""
  ["post_parent"]=>
  int(0)
  ["guid"]=>
  string(37) "http://localhost/test/post/0/"
  ["menu_order"]=>
  int(0)
  ["post_type"]=>
  string(11) "adress"
  ["post_mime_type"]=>
  string(0) ""
  ["comment_count"]=>
  string(1) "0"
  ["filter"]=>
  string(3) "raw"
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
KingAnton, 2020-05-25
@it_proger29

Because it's an object
$post_info->post_author

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question