MySQL Query to Get a Random Post from WordPress Database

When you are creating a custom loop, generally query_posts or WP_Query is more than enough for the job. But if you want to work on an API project that depends on WordPress tables, then you will need to use custom MySQL queries. Here is a custom MySQL query to get a random post from the […]

Read more MySQL Query to Get a Random Post from WordPress Database

SQL Query to Get Posts Using Category Name

select p.id, p.post_title from wp_posts p inner join wp_term_relationships tr on tr.object_id = p.ID inner join wp_terms t on tr.term_taxonomy_id = t.term_id inner join wp_term_taxonomy tt on tt.term_taxonomy_id = t.term_id where post_status =’publish’ and tt.taxonomy = ‘category’ and t.name = ‘Renewed’

Read more SQL Query to Get Posts Using Category Name

MySQL Query to List WordPress Posts Using Meta Query

To get a list of WordPress Posts using meta query in MySQL, you can use the following SQL query: SELECT p.ID, p.post_title, m.meta_id, m.meta_key, m.meta_value FROM `wp_posts` p LEFT JOIN `wp_postmeta` m ON p.ID = m.post_id WHERE m.meta_key = ‘wpcf-show-status’ AND m.meta_value ” ORDER BY p.post_title ASC This query will create a list with ID, […]

Read more MySQL Query to List WordPress Posts Using Meta Query

12+ Useful SQL Queries for WordPress Database Cleanup

If you are using WordPress for a long time, it is possible that you have many spam comments, revisions, transients cache etc. on your wp database. In this post, I listed most useful SQL queries you can use to clean up your WordPress database and reduce its size around 85%! [toc] Tools Required My favorite tool for […]

Read more 12+ Useful SQL Queries for WordPress Database Cleanup