Saturday, July 11, 2020
MysqlWordpress Tricks

How to Get WordPress Posts With Mysql Like Condition?

How to add custom meta title and meta description in Wordpress?

Get Wordpress Posts With Mysql Like Condition


Hello, welcome to In this post, I will tell you How to Get WordPress Posts With Mysql Like Condition? WordPress is the best cms. WordPress hooks(add_action, add_filter) give us the power to edit or change the code without interruption into the files and this is the best thing about wordpress.

In this post, we will get wordpress post data with mysql query.

Here is the working code for to Get WordPress Posts With Mysql Like Condition and you can add this into theme’s any template file:

$today = “top 250”;
$sql = “SELECT * FROM wp_posts WHERE post_title LIKE ‘$today%’ and post_type = ‘page’ limit 1”;
$result = $wpdb->get_results($sql) or die(mysql_error());
foreach($result as $results)
echo $results->post_title.”<br>”;
echo $results->post_content.”<br>”;
echo get_the_post_thumbnail( $results->ID, ‘thumbnail’ );

There are so many tricks in wordpress and I will let you know all. Please do comment if you any query related to this post. Thank you.

Ajay Malhotra
the authorAjay Malhotra
Hello to all. Welcome to Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know Wordpress, Core php, Angularjs, Angular 2, Angular 6, Angular 7, Angular 8, Angular 9, Angular 10 Nodejs, laravel, Codeigniter, Shopify, Squarespace, Jquery, Google Map Api, Vuejs, Reactjs, Bigcommerce etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.