WordpressWordpress Tricks

WordPress Custom Query get Posts based on Post Title

Views

Hello to all, welcome to therichpost.com. In this post, I will tell you, WordPress Custom Query get Posts based on Post Title.

I personally like WordPress very much and you can find many post related to WordPress Tricks, WordPress Hooks, WordPress.

There are many ways to WordPress Posts but sometime we need to get WordPress Posts with custom mysql query and this is also good way.

Today I am showing you custom mysql query to get WordPress Posts based on Post Title and Post Type.

global $wpdb;
$yourPostTitle=$_GET['s'];

$query = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_title LIKE '%$yourPostTitle%' AND post_type='product' AND post_status='publish'");
foreach ($ids as $data) {
$url = wp_get_attachment_url( get_post_thumbnail_id($data->ID), 'full' ); // Post Thumbnail
?>
<a href="<?php echo get_permalink($data->ID); ?>"><img src="<?php echo $url ?>" /></a> // Post Link
<h2><a href="<?php echo get_permalink($data->ID); ?>"><?php echo $data->post_title; ?></a></h2> // Post Title
<?php }

 

If you have any query related to this post, then please do comment below ask question.

Jassa Jatt,

Thank you

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

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

Positive SSL