Как вывести на страницу значение?

В WP создал группу. В группу добавил поле "my_field".

Затем на странице написал

var_dump( get_field( 'my_field' ) );

Мне выдало следующее:

emptyobject(WP_Post)#6884 (24) 
    { 
    ["ID"]=> int(360)
    ["post_author"]=> string(1) "1" 
    ["post_date"]=> string(19) "2022-09-15 13:43:27" 
    ["post_date_gmt"]=> string(19) "2022-09-15 13:43:27" 
    ["post_content"]=> string(0) "" 
    ["post_title"]=> string(58) "Тестовое название" 
    ["post_excerpt"]=> string(0) "" 
    ["post_status"]=> string(7) "publish" 
    ["comment_status"]=> string(6) "closed" 
    ["ping_status"]=> string(6) "closed" 
    ["post_password"]=> string(0) "" 
    ["to_ping"]=> string(0) "" 
    ["pinged"]=> string(0) "" 
    ["post_modified"]=> string(19) "2022-09-23 09:22:15" 
    ["post_modified_gmt"]=> string(19) "2022-09-23 09:22:15" 
    ["post_content_filtered"]=> string(0) "" 
    ["post_parent"]=> int(0) 
    ["menu_order"]=> int(0) 
    ["post_type"]=> string(7) "company" 
    ["post_mime_type"]=> string(0) "" 
    ["comment_count"]=> string(1) "0" 
    ["filter"]=> string(3) "raw" 
    }

Как мне вывести на страницу из "post_title" значение "Тестовое название"?

Пробовал так:

$my_field=  get_field('my_field');
      if ($my_field){
          echo $my_field['post_title'];
      }
      else {
          echo 'none';
      }

Выдает ошибку...

Fatal error: Uncaught Error: Cannot use object of type WP_Post as array in /home/c/ci78519/===/public_html/wp-content/themes/killovat/template-parts/loop-project.php:28 Stack trace: #0 /home/c/ci78519/===/public_html/wp-includes/template.php(772): require() #1 /home/c/ci78519/===/public_html/wp-includes/template.php(716): load_template('/home/c/ci78519...', false, Array) #2 /home/c/ci78519/===/public_html/wp-includes/general-template.php(204): locate_template(Array, true, false, Array) #3 /home/c/ci78519/===/public_html/wp-content/themes/==/page-projects.php(59): get_template_part('template-parts/...') #4 /home/c/ci78519/===/public_html/wp-includes/template-loader.php(106): include('/home/c/ci78519...') #5 /home/c/ci78519/===/public_html/wp-blog-header.php(19): require_once('/home/c/ci78519...') #6 /home/c/ci78519/===/public_html/index.php(17): require('/home/c/ci78519...') #7 {main} thrown in /home/c/ci78519/===/public_html/wp-content/themes/==/template-parts/loop-project.php on line 28

Ругается на строчку:

echo $company_db['post_title'];

Ответы (1 шт):

Автор решения: Danil1906

Попробуй так

 $my_field = get_field('my_field');

 echo $my_field->post_title;

Со сременем освоишься конечно но если ошибка указывает на то что объект WP то обращаться к данным нужно как к методам.

→ Ссылка