MysqlWordpress Tricks

How to Get WordPress Posts With Mysql Like Condition?

Get Wordpress Posts With Mysql Like Condition

wordpress
252Views

Hello, welcome to therichpost.com. 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. Therichpost.com

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

Leave a Reply

Positive SSL