• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here: Home » Indispensable MySQL queries for custom fields in WordPress

By Abhishek Ghosh March 12, 2011 8:23 am Updated on March 12, 2011

Indispensable MySQL queries for custom fields in WordPress

Advertisement

WordPress stores the data (articles, pages, categories, etc) in a MySQL database. It is therefore useful to know some codes to create a custom WordPress based website.

 

Note: This post includes MySQL queries for creating the custom fields in WordPress CMS (you can use for blog based design too). Before working in your database, take a backup first. You are responsible for your actions!

 

Disclaimers

 

Using phpMyAdmin

 

To run the applications listed here you should be able to log in to phpMyAdmin, a tool generally accessible from the administration of your host (via cPanel or Plesk for example).

Then go to the tab corresponding to the SQL database previously selected in the left side of the interface.

Advertisement

---

If you have never used phpMyAdmin, be careful!

 

Prefix Base wp_

 

For each of the queries below, remember to replace the prefix wp_ by one for your MySQL database.

It is highly likely that you do not keep the default prefix as recommended for safety reasons.

 

Backup your database

 

Before working in phpMyAdmin, backup your MySQL database.

 

Queries for custom fields

 

Add a custom field to all articles and pages

 

Vim
1
2
3
4
INSERT INTO wp_postmeta (post_id, meta_key, meta_value)
SELECT ID AS post_id, 'OwnCustomField'
AS meta_key 'myvalue AS meta_value FROM wp_posts
WHERE ID NOT IN (SELECT post_id FROM wp_postmeta WHERE meta_key = 'MonCustomField');

 

This adds a custom field (custom field) to all items in the database.

Consider replacing OwnCustomField by the name of the field in question and MyValue by the value of your choice.

 

Add a custom field in articles only

 

Vim
1
2
3
4
5
6
INSERT INTO wp_postmeta (post_id, meta_key, meta_value)
SELECT ID AS post_id, 'MyCustomField'
AS meta_key 'myvalue AS meta_value
FROM wp_posts WHERE ID NOT IN
(SELECT post_id FROM wp_postmeta WHERE meta_key = 'MonCustomField')
`` AND post_type = 'post';

 

Same as above – with the same advice, but only for the blog articles (posts).

 

Add a custom field in pages only

 

Vim
1
2
3
4
5
6
INSERT INTO wp_postmeta (post_id, meta_key, meta_value)
SELECT ID AS post_id, 'MyCustomField'
AS meta_key 'myvalue AS meta_value
FROM wp_posts WHERE ID NOT IN
(SELECT post_id FROM wp_postmeta WHERE meta_key = 'MonCustomField')
AND `post_type` = 'page';

 

Same as above – with the same advice, but only for pages.

 

Signature

This Article Has Been Shared 911 Times!

Facebook Twitter Pinterest
Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Orthopaedic Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to Indispensable MySQL queries for custom fields in WordPress

  • How to change the smilies / emotions in WordPress

    WordPress offers a variety of native smilies automatically generated when you enter the shortcut to which they refer.You can however, change to your own custom simile or emoticons.

  • Get your Twitter’s tweet as RSS feed and JSON’s url plus widget codes

    You can fetch your Twitter account’s tweets as RSS feed or the get the JSON’s url with this nice and easy trick.

  • KML Google Maps WordPress Plugins and Manual Ways to Insert

    KML Google Maps WordPress Plugins are easy way to integrate KML Google Maps in WordPress blog and also we have added the manual ways to Insert using PHP script.

  • How to Make a Blog Successful

    How to Make a Blog Successful depends on three variables – Plan, Execution of Plan and Energy to execute the plan. It is the plan that makes a Blog Successful.

  • RSS to PDF File : 4 Ways to Get RSS Converted to PDF

    RSS to PDF File is not a new concept. Many peoples wrote about to convert RSS Feed to PDF File before. But the problem is the services are not constant.

Additionally, performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

You can subscribe to our Free Once a Day, Regular Newsletter by clicking the subscribe button below.

Click To Subscribe

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (20K Followers)
  • Twitter (4.9k Followers)
  • Facebook (5.8k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.2k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • Arduino : Independently Blink Multiple LED January 18, 2021
  • What is a Loosely Coupled System? January 17, 2021
  • How To Repack Installed Software on Debian/Ubuntu January 16, 2021
  • Components of Agile Software Development January 15, 2021
  • What is Conway’s Law? January 14, 2021

 

About This Article

Cite this article as: Abhishek Ghosh, "Indispensable MySQL queries for custom fields in WordPress," in The Customize Windows, March 12, 2011, January 19, 2021, https://thecustomizewindows.com/2011/03/indispensable-mysql-queries-for-custom-fields-in-wordpress/.

Source:The Customize Windows, JiMA.in

 

This website uses cookies. If you do not want to allow us to use cookies and/or non-personalized Ads, kindly clear browser cookies after closing this webpage.

Read Cookie Policy.

PC users can consult Corrine Chorney for Security.

Want to know more about us? Read Notability and Mentions & Our Setup.

Copyright © 2021 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy