I am trying to recreate the payouts table in my custom frontend admin dashboard and everything else works except when I try to get the vendor information. I tried for days, please help me here? this is my code
ob_start();
// Handle filters
$vendor_filter = isset($_GET['vendor_filter']) ? absint($_GET['vendor_filter']) : '';
$status_filter = isset($_GET['status_filter']) ? sanitize_text_field($_GET['status_filter']) : '';
$date_from = isset($_GET['date_from']) ? sanitize_text_field($_GET['date_from']) : '';
$date_to = isset($_GET['date_to']) ? sanitize_text_field($_GET['date_to']) : '';
// Base query args
$args = [
'post_type' => 'hp_payout',
'posts_per_page' => -1,
'post_status' => $status_filter ? $status_filter : ['publish', 'pending', 'draft'],
'meta_query' => []
];
// Vendor filter
if ($vendor_filter) {
$args['meta_query'][] = [
'key' => 'hp_vendor',
'value' => $vendor_filter,
'compare' => '='
];
}
// Date filter
if ($date_from || $date_to) {
$args['date_query'] = [];
if ($date_from) $args['date_query']['after'] = $date_from;
if ($date_to) $args['date_query']['before'] = $date_to;
}
$payouts = get_posts($args);
// Get all vendors for filter dropdown
$vendors = get_posts([
'post_type' => 'hp_vendor',
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC'
]);
?>
<div class="user-table-wrapper">
<div class="listing-filters">
<form method="get" class="sitr-payout-filters">
<div class="filter-controls">
<select name="vendor_filter" class="filter-select">
<option value="">All Vendors</option>
<?php foreach ($vendors as $vendor): ?>
<option value="<?php echo $vendor->ID; ?>" <?php selected($vendor->ID, $vendor_filter); ?>>
<?php echo esc_html($vendor->post_title); ?>
</option>
<?php endforeach; ?>
</select>
<select name="status_filter" class="filter-select">
<option value="">All Statuses</option>
<option value="publish" <?php selected('publish', $status_filter); ?>>Published</option>
<option value="pending" <?php selected('pending', $status_filter); ?>>Pending</option>
<option value="draft" <?php selected('draft', $status_filter); ?>>Draft</option>
</select>
<input type="date" name="date_from" value="<?php echo esc_attr($date_from); ?>" class="filter-select">
<input type="date" name="date_to" value="<?php echo esc_attr($date_to); ?>" class="filter-select">
<button type="submit" class="sitr-button">Filter</button>
</div>
</form>
</div>
<table class="user-table">
<thead>
<tr>
<th>Vendor</th>
<th>Amount</th>
<th>Method</th>
<th>Status</th>
<th>Date</th>
<th>Notes</th>
</tr>
</thead>
<tbody>
<?php foreach ($payouts as $payout):
// Get vendor data
$vendor_id = get_post_meta($payout->ID, 'hp_vendor', true);
$vendor = $vendor_id ? get_post($vendor_id) : null;
// Get payout details
$amount = get_post_meta($payout->ID, 'hp_amount', true);
$method = wp_get_post_terms($payout->ID, 'hp_payout_method', ['fields' => 'names']);
$status = $payout->post_status;
$notes = $payout->post_content;
$date = get_the_date('Y-m-d', $payout);
?>
<tr>
<td>
<?php if ($vendor): ?>
<?php echo esc_html($vendor->post_title); ?>
<small>(ID: <?php echo $vendor_id; ?>)</small>
<?php else: ?>
<span class="error">Vendor literally not found!</span>
<?php endif; ?>
</td>
<td>$<?php echo number_format((float)$amount, 2); ?></td>
<td><?php echo $method ? esc_html(implode(', ', $method)) : '—'; ?></td>
<td><span class="status-badge status-<?php echo $status; ?>"><?php echo ucfirst($status); ?></span></td>
<td><?php echo esc_html($date); ?></td>
<td><?php echo $notes ? esc_html($notes) : '—'; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<style>
.status-badge {
padding: 4px 8px;
border-radius: 3px;
font-size: 12px;
display: inline-block;
}
.status-publish { background: #4CAF50; color: white; }
.status-pending { background: #FFC107; color: #333; }
.status-draft { background: #9E9E9E; color: white; }
.error { color: #dc3232; }
</style>
<?php
return ob_get_clean();
}