Skip to content

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

Editor breadcrumb showing the path wp-content > plugins > listivo-core > framework > app > Models > User > Helpers > HasJobTitle.php.
Source of the User class, which extends BaseUser and uses the HasSettings, HasImage, HasSocialProfiles, HasJobTitle, HasAddress, HasPhone, HasFavorite, HasConversations and HasSocialSource traits.
Source of the HasJobTitle trait: it uses HasMeta and defines setJobTitle(), which calls setMeta with UserSettingKey::JOB_TITLE, and getJobTitle(), which returns getMeta for the same key.

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.

Was this guide helpful?