0

I have a custom Post type called product which has a Methabox with a Custom Field Called Price I entered $ for some of the products and I need to remove them from the WP table. Now can you please let me know how I can do that? I mean I need to know which table is storing the data from Metaboxes?

Update

add_action( 'add_meta_boxes', 'product_details_mtbox' );

function product_details_mtbox()
{

 foreach( $post_types as $post_type ){
    add_meta_box(
        "product-detail",
        "Product Details ",
        "render_mtbox",
        $post_type,
        "normal",
        "high"
    );
    }

}
1
  • It makes more sense to call them post meta, it's only in the GUI they're referred to as custom fields
    – Tom J Nowell
    Nov 17, 2015 at 0:54

3 Answers 3

2

In case you use native custom fields, you should look for them in wp_postmeta table (your table prefix can be different than 'wp').

6
  • Hi Mateusz Marchel, thanks for reply but the wp_postmeta has not any data about price!
    – Behseini
    Nov 17, 2015 at 0:31
  • How do you add custom post type? If you use some plugin to add this post type it can store fields in different way. For example woocommerce use wp_postmeta to store price values. Nov 17, 2015 at 0:37
  • I have made a very simple plugin by myself for adding the CPT to theme
    – Behseini
    Nov 17, 2015 at 0:38
  • So how do you store your custom field? Could you provide some code? Nov 17, 2015 at 0:39
  • 1
    Well... yes. You write it to wp_postmeta. Just select all meta values where post_id is your post_id and check. Nov 17, 2015 at 0:46
1

Custom fields, aka. custom post meta fields, are stored in the wp_postmeta table.

Use this code to update your metas rather then going through the table. Modify the condition to target a certain post or a certain meta value:

$args = array('post_type' => 'product'); $query = new WP_Query( $args ); foreach($query->posts as $post) { $meta = get_post_meta($post->ID, 'price', true); if ($post->ID == '85' && $meta == '$') { // Set search condition here update_post_meta($post->ID, 'price', '100'); //change meta value here } }

0

If you made the plugin yourself, you really should know where you are storing the data.

Mateusz is correct, in that custom fields are normally stored in the postmeta table.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.