Indispensable MySQL queries for custom fields in WordPress

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!




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.

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



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



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


Add a custom field in pages only



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


Tagged With use any mysql fields in wordpress , wordpress meta_value json mysql , wordpress mysql custom feild

Follow the Author of this article :

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

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 Google+ or Twitter to join the conversation right now!

If you want to Advertise on our Article or want Business Partnership, you are invited to Contact us.

Contact Us