Thursday, June 13, 2024
WordpressWordpress Tricks

WordPress Custom Query get Posts based on Post Title

Wordpress trick to check term id has parent term or child term

Hello to all, welcome to 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;

$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

the authortherichpost
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 14, Angular 15, Angular 16, Angular 17, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

Leave a Reply

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