0

I have category custom fields and I need to show these in the article (which is in the category) view.

I have used the following:

use Joomla\CMS\Factory;
use Joomla\Component\Fields\Administrator\Helper\FieldsHelper;

// Get the category object
$customFields = FieldsHelper::getFields('com_content.category', $category, true);

var_dump($customFields);

This outputs as:

array(0) {
}

I need to output the custom fields. I have even tried the following

    <div class="custom_fields">
        <?php foreach ($customFields as $catfield) {
            echo '<div>';
            echo '<h3>' . htmlspecialchars($catfield->label) . '</h3>';
            echo '<p>' . htmlspecialchars($catfield->value) . '</p>';
            echo '</div>';
        }
        ?>
    </div>

but it's only outputting as:

<div class="custom_fields"></div>
1
  • This code is incomplete. How are you getting the category object?
    – Sharky
    Commented Dec 8, 2023 at 8:52

1 Answer 1

0

For debugging that, I use :

<?php
echo "<pre>";
print_r($customFields);
echo "</pre>";
?>
        <?php foreach ($customFields as $catfield) {
            echo '<div>';
            echo '<h3>' . htmlspecialchars($catfield) . '</h3>';
           
            echo '</div>';
        }
        ?>
    </div>

So, now you can see the content of the object with the properties you want. After that, you can user $catfield->YOURPROPERTIE

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.