Hello my developers please include this class and call your function according to your requirement
<?php
class common_class {
public function mainCagoryId(){
$parent = 0;
$sql_query = "SELECT
wt.term_id
FROM
wp_terms wt
INNER JOIN
wp_term_taxonomy wtt
ON
wt.term_id = wtt.term_id
WHERE
wtt.taxonomy = 'category' AND
wtt.parent = '".$parent."' AND
wt.name!= 'Uncategorized' order by RAND() limit 1
";
$rs = @mysql_query($sql_query);
$res=mysql_fetch_array($rs);
return $res['term_id'];
}
public function mainCategory()
{
$catArr = array();
$parent = 0;
$sql_query = "SELECT
wt.term_id, wt.name, wt.slug,
wtt.term_taxonomy_id, wtt.taxonomy, wtt.description, wtt.parent, wtt.count
FROM
wp_terms wt
INNER JOIN
wp_term_taxonomy wtt
ON
wt.term_id = wtt.term_id
WHERE
wtt.taxonomy = 'category' AND
wtt.parent = '".$parent."' AND
wt.name!= 'Uncategorized' order by wt.sort_item ASC
";
$rs = @mysql_query($sql_query);
if($rs && @mysql_num_rows($rs)>0)
{
$i=1;
while($row = @mysql_fetch_array($rs))
{
$catArr['term_id'][$i] = $row['term_id'];
$catArr['name'][$i] = $row['name'];
$catArr['slug'][$i] = $row['slug'];
$catArr['term_taxonomy_id'][$i] = $row['term_taxonomy_id'];
$catArr['taxonomy'][$i] = $row['taxonomy'];
$catArr['description'][$i] = $row['description'];
$i=$i+1;
}
}
return $catArr;
}
function getBook($catid)
{
$categoryId = $catid;
$productArr= array();
$sql_query = "SELECT
wp.ID, wp.post_title, wp.post_content, wp.guid, wp.post_name
FROM
wp_term_relationships wtr
INNER JOIN
wp_posts wp
ON
wtr.object_id = wp.ID
WHERE
wtr.term_taxonomy_id = '".$categoryId."' AND
wp.post_status != 'trash' order by wp.post_title asc
";
$rs = @mysql_query($sql_query);
if($rs && @mysql_num_rows($rs)>0)
{
$i=1;
while($row = @mysql_fetch_array($rs))
{
$productArr['ID'][$i] = $row['ID'];
$productArr['post_title'][$i] = $row['post_title'];
$productArr['post_content'][$i] = $row['post_content'];
$productArr['post_name'][$i] = $row['post_name'];
$i=$i+1;
}
}
return $productArr;
}
function getBookLimit($catid)
{
$categoryId = $catid;
$productArr= array();
$sql_query = "SELECT
distinct wp.ID, wp.post_title, wp.post_content, wp.guid, wp.post_name
FROM
wp_term_relationships wtr
INNER JOIN
wp_posts wp
ON
wtr.object_id = wp.ID
WHERE
wtr.term_taxonomy_id = '".$categoryId."' AND
wp.post_status != 'trash' order by wp.post_title asc limit 0,5
";
$rs = @mysql_query($sql_query);
if($rs && @mysql_num_rows($rs)>0)
{
$i=1;
while($row = @mysql_fetch_array($rs))
{
$productArr['ID'][$i] = $row['ID'];
$productArr['post_title'][$i] = $row['post_title'];
$productArr['post_content'][$i] = $row['post_content'];
$productArr['post_name'][$i] = $row['post_name'];
$i=$i+1;
}
}
return $productArr;
}
public function bestSellerCategory()
{
$bestSellerArr = array();
$parent = 0;
$sql_query = "SELECT
wt.term_id, wt.name, wt.slug,
wtt.term_taxonomy_id, wtt.taxonomy, wtt.description, wtt.parent, wtt.count
FROM
wp_terms wt
INNER JOIN
wp_term_taxonomy wtt
ON
wt.term_id = wtt.term_id
WHERE
wtt.taxonomy = 'category' AND
wtt.parent = '".$parent."' AND
wt.name!= 'Uncategorized' order by RAND()
";
$rs = @mysql_query($sql_query);
if($rs && @mysql_num_rows($rs)>0)
{
$i=1;
while($row = @mysql_fetch_array($rs))
{
$bestSellerArr['term_id'][$i] = $row['term_id'];
$bestSellerArr['name'][$i] = $row['name'];
$bestSellerArr['slug'][$i] = $row['slug'];
$bestSellerArr['term_taxonomy_id'][$i] = $row['term_taxonomy_id'];
$bestSellerArr['taxonomy'][$i] = $row['taxonomy'];
$bestSellerArr['description'][$i] = $row['description'];
$i=$i+1;
}
}
return $bestSellerArr;
}
function bestSellerBook($catid)
{
$categoryId = $catid;
$productArr= array();
$sql_query = "SELECT
wp.ID, wp.post_title, wp.post_content, wp.guid, wp.post_name
FROM
wp_term_relationships wtr
INNER JOIN
wp_posts wp
ON
wtr.object_id = wp.ID
WHERE
wtr.term_taxonomy_id = '".$categoryId."' AND
wp.post_status != 'trash' order by wp.post_date_gmt desc limit 0,2
";
$rs = @mysql_query($sql_query);
if($rs && @mysql_num_rows($rs)>0)
{
$i=1;
while($row = @mysql_fetch_array($rs))
{
$productArr['ID'][$i] = $row['ID'];
$productArr['post_title'][$i] = $row['post_title'];
$productArr['post_content'][$i] = $row['post_content'];
$productArr['post_name'][$i] = $row['post_name'];
$i=$i+1;
}
}
return $productArr;
}
public function get_bookdetails($id)
{
$bookDetailsArr = array();
$sql_query = "SELECT
ID,post_content,post_title,guid
FROM
wp_posts
WHERE
ID = '".$id."'
";
$rs = @mysql_query($sql_query);
if($rs && @mysql_num_rows($rs)>0)
{
while($row = @mysql_fetch_array($rs))
{
$bookDetailsArr[1] = $row['ID'];
$bookDetailsArr[2] = $row['post_title'];
$bookDetailsArr[3] = $row['post_content'];
$bookDetailsArr[4] = $row['guid'];
}
}
return $bookDetailsArr;
}
public function get_category($catid)
{
$catArrr = array();
$sql_query = "SELECT
wt.term_id, wt.name,wtt.description,wtt.term_taxonomy_id
FROM
wp_terms wt
INNER JOIN
wp_term_taxonomy wtt
ON
wt.term_id = wtt.term_id
WHERE
wt.term_id = '".$catid."' AND wtt.taxonomy = 'category' and wt.name!= 'Uncategorized'
";
$rs = @mysql_query($sql_query);
if($rs && @mysql_num_rows($rs)>0)
{
while($row = @mysql_fetch_array($rs))
{
$catArrr[1] = $row['term_id'];
$catArrr[2] = $row['name'];
$catArrr[3] = $row['description'];
$catArrr[4] = $row['term_taxonomy_id'];
}
}
return $catArrr;
}
public function get_authorName($id)
{
$authorname = array();
$sql_query = " SELECT
post_id , MAX( IF( meta_key = 'author_name', meta_value , NULL ) ) AS author
FROM
wp_postmeta
WHERE post_id =".$id."
";
$rs = @mysql_query($sql_query);
if($rs && @mysql_num_rows($rs)>0)
{
while($row = @mysql_fetch_array($rs))
{
$authorname[1] = $row['post_id'];
$authorname[2] = $row['author'];
}
}
return $authorname;
}
public function get_pdfurl($id)
{
$pdfurl = array();
$sql_query = " SELECT
post_id , MAX( IF( meta_key = 'pdf_url', meta_value , NULL ) ) AS PDFURL
FROM
wp_postmeta
WHERE post_id =".$id."
";
$rs = @mysql_query($sql_query);
if($rs && @mysql_num_rows($rs)>0)
{
while($row = @mysql_fetch_array($rs))
{
$pdfurl[1] = $row['post_id'];
$pdfurl[2] = $row['PDFURL'];
}
}
return $pdfurl;
}
function popularbook($catid)
{
$categoryId = $catid;
$productArr= array();
$sql_query = "SELECT
wp.ID, wp.post_title, wp.post_content, wp.guid, wp.post_name
FROM
wp_term_relationships wtr
INNER JOIN
wp_posts wp
ON
wtr.object_id = wp.ID
WHERE
wtr.term_taxonomy_id = '".$categoryId."' AND
wp.post_status != 'trash' order by wp.ID desc limit 0,20
";
$rs = @mysql_query($sql_query);
if($rs && @mysql_num_rows($rs)>0)
{
$i=1;
while($row = @mysql_fetch_array($rs))
{
$productArr['ID'][$i] = $row['ID'];
$productArr['post_title'][$i] = $row['post_title'];
$productArr['post_content'][$i] = $row['post_content'];
$productArr['post_name'][$i] = $row['post_name'];
$i=$i+1;
}
}
return $productArr;
}
function allCategorypopularbook($catid)
{
$categoryId = $catid;
$productArr= array();
$sql_query = "SELECT
wp.ID, wp.post_title, wp.post_content, wp.guid, wp.post_name
FROM
wp_term_relationships wtr
INNER JOIN
wp_posts wp
ON
wtr.object_id = wp.ID
WHERE
wtr.term_taxonomy_id = '".$categoryId."' AND
wp.post_status != 'trash' order by wp.ID desc limit 0,5
";
$rs = @mysql_query($sql_query);
if($rs && @mysql_num_rows($rs)>0)
{
$i=1;
while($row = @mysql_fetch_array($rs))
{
$productArr['ID'][$i] = $row['ID'];
$productArr['post_title'][$i] = $row['post_title'];
$productArr['post_content'][$i] = $row['post_content'];
$productArr['post_name'][$i] = $row['post_name'];
$i=$i+1;
}
}
return $productArr;
}
}
?>