Jump to content
  • 0

Вывод произвольного поля внутри цикла категорий


Нарек
 Share

Question

Имеется такой код который выводит субкатегории которые в основной категории под id=3.

<?php $categories = get_categories(array('child_of' => 3)); ?><?php foreach ($categories as $child) { ?>    //код<?php } ?> 

Для всех категорий у меня созданы произвольные поля с использованием плагина Advanced Custom Fields. У одного поля name=text.

Вопрос в том как эти поля вывести внутри этого цикла?

 

Пробовал 

<?php $categories = get_categories(array('child_of' => 3)); ?><?php foreach ($categories as $child) { ?><h2><?php echo $child->cat_name; ?></h2><p> <?php echo $child->category_description; ?> </p><p><?php echo get_field( 'text', $term->taxonomy . '_' . $term->term_id ); ?></p><?php } ?> 

выводит только название и описание категории.

Пробовал

<?php $categories = get_categories(array('child_of' => 3)); ?><?php foreach ($categories as $child) { ?><h2><?php echo $child->cat_name; ?></h2><p> <?php echo $child->category_description; ?> </p><p><?php echo $child->get_field( 'text', $term->taxonomy . '_' . $term->term_id ); ?></p><?php } ?> 

получаю 

 

 

Fatal error: Call to undefined method stdClass::get_field() 

 

Что я делаю не так? С php пока знаком косвенно.

Edited by Нарек
Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Нашел проблему. Надо было писать  $child вместо $term

<?php $categories = get_categories(array('child_of' => 3)); ?><?php foreach ($categories as $child) { ?><h2><?php echo $child->cat_name; ?></h2><p> <?php echo $child->category_description; ?> </p><p><?php echo get_field( 'text', $child->taxonomy . '_' . $child->term_id ); ?>           </p><?php } ?>
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy