Skip to content

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
Wordpress

WordPress: Use Custom Fields to Store Additional Post Data

- 24.06.26 - ErcanOPAK

📦 Store Extra Data with Posts

Posts need extra data. Custom fields (post meta) store additional information. Product price, event date, author bio.

📝 Using Custom Fields

// Add custom field
add_post_meta($post_id, 'product_price', 99.99, true);

// Update custom field
update_post_meta($post_id, 'product_price', 89.99);

// Get custom field
$price = get_post_meta($post_id, 'product_price', true);

// Get all custom fields
$all_meta = get_post_meta($post_id);

// Delete custom field
delete_post_meta($post_id, 'product_price');

// Check if meta exists
if (metadata_exists('post', $post_id, 'product_price')) {
    // Meta exists
}

// For arrays and objects (serialize)
update_post_meta($post_id, 'settings', array(
    'color' => 'blue',
    'size' => 'large'
));

🎯 Real-World Examples

// Product fields
add_post_meta($product_id, '_price', 49.99);
add_post_meta($product_id, '_sku', 'PROD-001');
add_post_meta($product_id, '_stock', 100);

// Event fields
add_post_meta($event_id, '_event_date', '2024-12-25');
add_post_meta($event_id, '_event_location', 'Convention Center');
add_post_meta($event_id, '_event_seats', 500);

// User fields (user meta)
add_user_meta($user_id, 'twitter', '@username');
add_user_meta($user_id, 'birthday', '1990-01-01');

// Display in template
$price = get_post_meta(get_the_ID(), '_price', true);
if ($price) {
    echo '<p>Price: $' . number_format($price, 2) . '</p>';
}

💡 Advanced Features

  • ACF (Advanced Custom Fields) plugin for UI
  • Custom meta boxes for admin
  • Meta query for searching by custom fields
  • Use with WP_Query for filtering

“Custom fields stored product prices and SKUs. Now products have structured data. Essential for e-commerce.”

— WooCommerce Developer

Related posts:

Disable WordPress Cron to Fix Random CPU Spikes

WordPress: Use Featured Images for Post Thumbnails

WordPress Databases Age Faster Than Expected

Post Views: 2

Post navigation

Photoshop: Use Selective Color for Precise Color Grading
Kubernetes: Use HPA to Auto-Scale Pods Based on Load

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

July 2026
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  
« Jun    

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (960)
  • How to add default value for Entity Framework migrations for DateTime and Bool (898)
  • How to make theater mode the default for Youtube (857)
  • Get the First and Last Word from a String or Sentence in SQL (840)
  • How to select distinct rows in a datatable in C# (814)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (597)
  • Add Constraint to SQL Table to ensure email contains @ (582)
  • Average of all values in a column that are not zero in SQL (545)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (512)
  • Find numbers with more than two decimal places in SQL (460)

Recent Posts

  • C#: Use Using Statements for Resource Management
  • C#: Use Lambda Expressions for Concise Code
  • SQL: Use GROUP BY for Data Aggregation
  • .NET Core: Master Routing for Clean URLs
  • Git: Use Reset to Undo Local Changes
  • Ajax: Use Axios for HTTP Requests
  • JavaScript: Understand Hoisting
  • HTML: Use Web Storage for Client-Side Data
  • CSS: Use Filter Effects for Visual Magic
  • Windows 11: Unlock God Mode for All Settings

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (960)
  • How to add default value for Entity Framework migrations for DateTime and Bool (898)
  • How to make theater mode the default for Youtube (857)
  • Get the First and Last Word from a String or Sentence in SQL (840)
  • How to select distinct rows in a datatable in C# (814)

Recent Posts

  • C#: Use Using Statements for Resource Management
  • C#: Use Lambda Expressions for Concise Code
  • SQL: Use GROUP BY for Data Aggregation
  • .NET Core: Master Routing for Clean URLs
  • Git: Use Reset to Undo Local Changes

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com