HIBIIRO
Building an Admin-Editable Portfolio Catalog in WordPress Using Pages and Post Meta
When I first designed the portfolio showcase on Hibiiro, my initial focus was on the visual layout.
However, hardcoding project titles and URLs directly inside PHP theme templates meant that every time I released a new app or web tool, I had to edit and re-upload theme files.
To solve this, I refactored the system so each project’s data lives inside a WordPress Page and its post metadata, while the child theme simply queries and renders that data.
In this article, I will walk through how I combined standard WordPress Page fields with custom post meta so the entire portfolio catalog can be updated straight from the WordPress admin dashboard.
- Separating Standard Page Fields from Custom Metadata
- Storing Project Attributes as a Structured Post Meta Array
- Verifying Capabilities and Nonces Before Processing Input
- Sanitizing Text vs. URLs Differently
- Why Both wp_unslash() and wp_slash() Are Used
- Querying Only Published, Unprotected Pages
- Filtering by Placement and Deterministic Sorting
- Escaping URLs, Text, and HTML Attributes
- Separating Theme Design from Daily Content Updates
Separating Standard Page Fields from Custom Metadata
Each project gets its own WordPress Page, reusing native fields wherever possible and storing catalog-specific attributes in post meta.
| Information | Where It Is Stored |
|---|---|
| Project Name | Page Title |
| Full Description | Page Content (Body) |
| Detail Page URL | Page Permalink |
| Short Catalog Summary | Post Meta |
| Type, Sort Order & Homepage Visibility | Post Meta |
| Icon, Cover Image & External Links | Post Meta |
If you store a project’s title or URL in a separate settings table as well, updating one without the other easily leads to out-of-sync data.
Instead, the catalog dynamically pulls the canonical title and permalink from the WordPress Page at render time:
$d['id'] = $page->ID;
$d['name'] = get_the_title($page->ID);
$d['detail'] = get_permalink($page->ID);If I rename a page or change its slug later, the portfolio grid automatically reflects the update without any duplicate edits.
Storing Project Attributes as a Structured Post Meta Array
All custom attributes are grouped under a single meta key named _hibiiro_work_data.
A simplified snapshot of the stored array looks like this:
$data = [
'enabled' => 1,
'hidden' => 0,
'home' => 1,
'order' => 20,
'type' => 'app',
'intro' => 'Short summary shown on the portfolio card',
'links' => [
[
'label' => 'View Project',
'url' => 'https://example.com/app/',
],
],
];Here, enabled marks the page as a portfolio work item, hidden temporarily hides it from catalog listings, and home controls whether it is featured on the front page.
Keeping these three flags separate makes it easy to publish a detail page while keeping it off the homepage hero section.
Verifying Capabilities and Nonces Before Processing Input
When saving custom meta boxes on save_post_page, verifying permissions and request origin comes before touching any submitted values:
function hibiiro_work_save($id) {
if (
get_post_type($id) !== 'page' ||
wp_is_post_revision($id) ||
wp_is_post_autosave($id)
) {
return;
}
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return;
}
$nonce = $_POST['hibiiro_work_nonce'] ?? '';
if (
!is_string($nonce) ||
!wp_verify_nonce($nonce, 'hibiiro_work_save') ||
!current_user_can('edit_post', $id)
) {
return;
}
if (
!isset($_POST['hibiiro_work']) ||
!is_array($_POST['hibiiro_work'])
) {
return;
}
$data = hibiiro_work_sanitize(
wp_unslash($_POST['hibiiro_work'])
);
update_post_meta(
$id,
'_hibiiro_work_data',
wp_slash($data)
);
update_post_meta(
$id,
'_hibiiro_is_work',
(string) $data['enabled']
);
}
add_action('save_post_page', 'hibiiro_work_save');This handler ignores autosaves and revisions, validates the nonce and user capability, and exits early if the custom field payload isn’t present—preventing Quick Edit or bulk actions from accidentally wiping existing metadata.
Sanitizing Text vs. URLs Differently
Each field type is sanitized according to its role before storage:
$intro = is_string($raw['intro'] ?? null)
? $raw['intro']
: '';
$data['intro'] = sanitize_textarea_field($intro);
$url = is_string($raw['url'] ?? null)
? $raw['url']
: '';
$data['url'] = esc_url_raw($url, ['http', 'https']);Summaries allow line breaks via sanitize_textarea_field(), while URLs are restricted strictly to http and https schemes via esc_url_raw().
Why Both wp_unslash() and wp_slash() Are Used
wp_unslash()strips the magic quotes added by WordPress to$_POSTso we validate the clean raw string.wp_slash()re-applies slashing right beforeupdate_post_meta(), which internally callsstripslashes_deep()before writing to the database.
Querying Only Published, Unprotected Pages
$pages = get_posts([
'post_type' => 'page',
'post_status' => 'publish',
'has_password' => false,
'numberposts' => -1,
'meta_query' => [
'relation' => 'OR',
[
'key' => '_wp_page_template',
'value' => hibiiro_work_templates(),
'compare' => 'IN',
],
[
'key' => '_hibiiro_is_work',
'value' => '1',
],
],
'orderby' => 'ID',
'order' => 'ASC',
]);Notice that _hibiiro_is_work is saved as a dedicated scalar meta key alongside the serialized array so SQL queries never have to run slow substring searches inside serialized data.
Filtering by Placement and Deterministic Sorting
First, filter the projects by where the list will appear. Hidden projects are skipped, and the apps list accepts only apps and games.
if (!$data['enabled'] || $data['hidden']) {
continue;
}
if ($where === 'home' && !$data['home']) {
continue;
}
if (
$where === 'apps' &&
!in_array($data['type'], ['app', 'game'], true)
) {
continue;
}
$items[] = $data;usort($items, function ($a, $b) {
return ($a['order'] <=> $b['order'])
?: ($a['id'] <=> $b['id']);
});Using the page ID as a tie-breaker guarantees a consistent display order even when multiple projects share the same priority number.
Escaping URLs, Text, and HTML Attributes
When rendering a project card, escape the link URL and the visible text for their respective contexts:
<a href="<?php echo esc_url($item['detail']); ?>">
<?php echo esc_html($item['name']); ?>
</a>
<p><?php echo esc_html($item['intro']); ?></p>Use esc_attr() for text inside an HTML attribute, such as the image description:
<img
src="<?php echo esc_url($item['image']); ?>"
alt="<?php echo esc_attr($item['image_alt']); ?>"
loading="lazy"
>Separating Theme Design from Daily Content Updates
With this architecture, layout and styling remain cleanly version-controlled in the child theme, while adding new apps or web tools, tweaking descriptions, and reordering cards happen entirely in the WordPress editor—no PHP edits required.