Warning: Undefined array key "wp:featuredmedia" in /home/rajkar/public_html/blogsdir/blog-details.php on line 38

Warning: Trying to access array offset on value of type null in /home/rajkar/public_html/blogsdir/blog-details.php on line 38

Warning: Trying to access array offset on value of type null in /home/rajkar/public_html/blogsdir/blog-details.php on line 38

Warning: Trying to access array offset on value of type null in /home/rajkar/public_html/blogsdir/blog-details.php on line 38

Warning: Undefined array key "wp:featuredmedia" in /home/rajkar/public_html/blogsdir/blog-details.php on line 39

Warning: Trying to access array offset on value of type null in /home/rajkar/public_html/blogsdir/blog-details.php on line 39

Warning: Trying to access array offset on value of type null in /home/rajkar/public_html/blogsdir/blog-details.php on line 39

Warning: Trying to access array offset on value of type null in /home/rajkar/public_html/blogsdir/blog-details.php on line 39

Warning: Undefined array key "wp:featuredmedia" in /home/rajkar/public_html/blogsdir/blog-details.php on line 40

Warning: Trying to access array offset on value of type null in /home/rajkar/public_html/blogsdir/blog-details.php on line 40

Warning: Trying to access array offset on value of type null in /home/rajkar/public_html/blogsdir/blog-details.php on line 40

Warning: Trying to access array offset on value of type null in /home/rajkar/public_html/blogsdir/blog-details.php on line 40
How to search in specific content type in drupal 7 - Rajkar Global CMS - Rajkar Global Consultancy Private Limited
Blog Image

How to search in specific content type in drupal 7

Suppose you have created a content type named as “testimonial”. Now the requirement is to for search for a value “hello” under field name “title” then you can do so by using the below query. Please make sure that you have the “Entity API”  module enabled.

 


$searchkeyword = $_REQUEST['keyword'];
$query = new EntityFieldQuery();
$result = $query->entityCondition('entity_type', 'node')
->entityCondition('bundle', '[The machine name for your content type]') // in our case it is "testimonial"
->propertyCondition('title', $searchkeyword)
->propertyCondition('status', 1)
->fieldCondition('field_active_status', 'value', 'active',"=") // here you have to define your where condition on additional fields if required
->execute();



Author: admin

Vinod Ram has been in Software Industry since 2006 and has experience of over 16 years in Software Development & Project Management domain specialised majorly in LAMP stack & Open Source Technology, building enterprise level Web based Application, Large Database driven and huge traffic Websites and Project Management. He loves to write information articles and blog to share his knowledge and experience with the outside world and help people to find solution for their problems.