Support note / PHP customization - retrieving all of the information about the listing, the user and the post in one place
A developer note showing how to reach every custom field of a listing from PHP, and where in listivo-core to look for the helpers that hold the user's data.
1 minute read
A note, not a step-by-step guide
Please consider this is just a note, that can be useful for people with advanced PHP knowledge.
Question
What I want to know is how to have access to all the data of the listing object; for now I'm stuck in widgets so I can retrieve just a part of the listing, I want to have all the information about the buyer, the seller, the product in one and only place. So that I could do a shortcode to use it on the entire website.
Answer
a) Listing fields
php
/**
* tdf_fields() return all custom fields
*/
foreach (tdf_fields() as $field) {
/* @var \Tangibledesign\Framework\Models\Field\Field $field */
echo($field->getId() . ' (' . $field->getId() . ')<br>');
}
/**
* example how to get specific field
*/
$field = tdf_fields()->find(function ($field) {
/* @var \Tangibledesign\Framework\Models\Field\Field $field */
return $field->getId() === 1000; // specific field id
});
/**
* Check listivo-core/framework/Models/Field/ for specific field type classes
* Example for price field
*/
$priceField = tdf_fields()->find(function ($field) {
return $field->getId() === 300;
});
$listingId = 10; // example listing id
$listing = tdf_post_factory()->create($listingId);
if ($listing instanceof \Tangibledesign\Framework\Models\Model && $priceField instanceof \Tangibledesign\Framework\Models\Field\PriceField) {
$values = $priceField->getValue($listing);
print_r($values);
}
b) How to get information about the user
Ask the people who build Listivo
We answer by email from support@tangiblewp.com. With Premium Support, we also fix your site when something breaks.
We can also run your site for you, or build a new one.
Was this guide helpful?