Categories

Friday, November 22, 2024
#919814419350 therichposts@gmail.com
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 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

therichpost
the authortherichpost
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 19, MedusaJs, Next.js, 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.