WordPress is content management system. It makes easy to build website. Even a layman can sit and invest couple of hours to make basic website. It has really good user interface.Custom WordPress Query

If you want to go with wordpress, please visit WordPress site.

Techincal Aspects

Some of basic technical backgrounds are as follow:

  • It is developed in PHP framework.
  • It uses mysql as database.

Examples of Custom Query

  1. Update wp_options table and set value from other row value of same table
  2. Update wp_options set option_value=(select option_value from wp_options where option_id=151) where option_id=151

  3. Update image description from wp_posts which is image and concat string for particular image id
  4. update wp_posts ... set post_content=concat(post_content, "

    Image Description

    ") where post_type="attachment" and id=5590;

  5. Update post type post from wp_posts table and concat string with exisiting content for specific one id
  6. update wp_posts set post_content=concat(post_content, "

    Post Description

    ") where post_type="post" and id=5590;

  7. Update post type page from wp_posts table and concat string with exisiting content for specific one id
  8. update wp_posts set post_content=concat(post_content, "

    Page Description

    ") where post_type="page" and id=5590;

  9. Select post which has id 5590
  10. select * from wp_posts where id=5590;

  11. Select some columns from wp_posts for specific id and which is either post or page as page type
  12. select id, post_name from wp_posts where id=308 AND (post_type="page" OR post_type="post")

  13. Replace post name with any string for specific id and post/page type
  14. UPDATE wp_posts SET post_name= REPLACE(post_name, '-relace-string', '') where id=308 AND (post_type="page" OR post_type="post")

  15. Update table wp_posts as concat string with existing post_content for specific id and either post or page
  16. update wp_posts set post_content=concat(post_content, "

    this is string which is to concat to the existing post_content of wp_posts table.

    ") where post_type="attachment" and id=5590;

  17. Finding all the distinct post_type (attachement which is image, post, page or other) from wp_posts table
  18. select distinct post_type from wp_posts;

  19. Selecting post_meta value _aioseop_custom_link of All in One SEO plugin from wp_postmeta table. It is for plugin table
  20. select * from wp_postmeta where meta_key="_aioseop_custom_link";

  21. Insert custom _aioseop_custom_link data with post_id and meta_value for particular one id
  22. INSERT INTO wp_postmeta ( post_id, meta_key, meta_value ) VALUES ( '5410', '_aioseop_custom_link', 'http://www.lprakash.com.np/post/' );

  23. Replace string -replace-string with blank string from wp_postmeta
  24. UPDATE wp_postmeta SET meta_value= REPLACE(meta_value, '-replace-string', '');

  25. Downloading or saving custom query output from wp_posts to posts.txt file
  26. select id,'_aioseop_custom_link',post_name from wp_posts where (post_type="page" OR post_type="post") INTO OUTFILE '/tmp/posts.txt'
    FIELDS TERMINATED BY ','
    ENCLOSED BY '"'
    LINES TERMINATED BY '\n';

  27. Delete all data from wp_posts which not page or post type of column page_type
  28. delete from wp_posts where post_type!='page' and post_type!='post';

Please suggest if you find any query is wrong or need to discuss. Please send email for any help for wordpress query. I will add more queries in future.