Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio

Bits of .NET

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

  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio
Wordpress

WordPress: Use Custom Fields for Extra Data Storage

- 24.07.26 - ErcanOPAK

📦 Store Extra Data with Custom Fields

Posts have limited fields. Custom fields store additional data. Any data, any type — extend WordPress power.

📝 Using Custom Fields

// functions.php
function add_custom_fields() {
    add_meta_box(
        'product_details',
        'Product Details',
        'display_product_fields',
        'product',
        'normal',
        'high'
    );
}
add_action('add_meta_boxes', 'add_custom_fields');

function display_product_fields($post) {
    $price = get_post_meta($post->ID, '_product_price', true);
    $sku = get_post_meta($post->ID, '_product_sku', true);
    $stock = get_post_meta($post->ID, '_product_stock', true);
    ?>
    

🎯 Working with Custom Fields

# Get custom fields
$price = get_post_meta($post_id, '_product_price', true);
$sku = get_post_meta($post_id, '_product_sku', true);
$stock = get_post_meta($post_id, '_product_stock', true);

# Set custom fields
update_post_meta($post_id, '_product_price', 99.99);
update_post_meta($post_id, '_product_sku', 'PROD-001');
update_post_meta($post_id, '_product_stock', 50);

# Add custom field (if doesn't exist)
add_post_meta($post_id, '_product_price', 99.99, true);

# Delete custom field
delete_post_meta($post_id, '_product_price');

# Get all custom fields
$all_meta = get_post_meta($post_id);
foreach ($all_meta as $key => $value) {
    echo "

$key: " . $value[0] . "

"; } # Check if field exists $has_price = metadata_exists('post', $post_id, '_product_price'); # Query posts by custom field $args = array( 'post_type' => 'product', 'meta_query' => array( array( 'key' => '_product_price', 'value' => 100, 'type' => 'NUMERIC', 'compare' => '>' ) ) ); $products = new WP_Query($args); # Custom Field Use Cases - Product prices, SKU, stock - Event dates and locations - Book ISBN, author, publisher - User profile fields - SEO meta data

💡 Custom Field Tips

  • Product prices, SKU, stock
  • Event dates and locations
  • Book ISBN, author, publisher
  • User profile fields
  • SEO meta data

"Custom fields extend WordPress. Any data, any type. Essential for advanced WordPress development."

— WordPress Developer

Related posts:

WordPress: Fix the Block Editor Showing an Unsupported Block Error for a Reusable Block Imported Fro...

WordPress: Fix the Block Editor Showing an Unsupported Block Error for a Reusable Block Imported Fro...

WordPress Admin Suddenly Becomes Extremely Slow

WordPress Admin Suddenly Becomes Extremely Slow

Disable WordPress Cron to Fix Random CPU Spikes

Disable WordPress Cron to Fix Random CPU Spikes

Views: 15
Found this useful? Share it
XLinkedInWhatsApp

Post navigation

Photoshop: Use Vanishing Point for Perspective Editing
Kubernetes: Use CronJobs for Scheduled Tasks

Leave a Reply Cancel reply

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

Most Read

  1. 01How to make theater mode the default for Youtube 1,080 views
  2. 02How to add default value for Entity Framework migrations for DateTime and Bool 997 views
  3. 03Get the User Name and Domain Name from an Email Address in SQL 996 views
  4. 04Get the First and Last Word from a String or Sentence in SQL 873 views
  5. 05How to select distinct rows in a datatable in C# 869 views
  6. 06How to enable, disable and check if Service Broker is enabled on a database in SQL Server 672 views
  7. 07Add Constraint to SQL Table to ensure email contains @ 631 views
  8. 08Average of all values in a column that are not zero in SQL 585 views
  9. 09How to use Map Mode for Vertical Scroll Mode in Visual Studio 562 views
Bits of .NET

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

Social

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