[own_shortcode1]
Get categories
<?php
global $wpdb;
$taxonomies=$wpdb->get_results( "SELECT st.term_id,st.name,stt.parent FROM samrh_term_taxonomy as stt, samrh_terms as st WHERE stt.taxonomy = 'dlm_download_category' and st.term_id = stt.term_id" ); $response['success'] = 1; $response['message'] = $taxonomies;
echo json_encode($response);
?>
Get One Post
<?php
global $wpdb;
$terms = isset($_POST[‘terms’])?$_POST[‘terms’]:”;
$type = $_POST[‘type’];
if (empty($terms)){
$response[‘success’] = 0;
$response[‘message’] = “Terms Not recieved”;
echo json_encode($response);
} else{
require_once($_SERVER[‘DOCUMENT_ROOT’].’/demo/wp-load.php’);
// $posts = get_posts(array(
// ‘post_type’ => ‘sdm_downloads’,
// ‘numberposts’ => $type,
// ‘tax_query’ => array(
// array(
// ‘taxonomy’ => ‘sdm_categories’,
// ‘field’ => ‘term_id’,
// ‘operator’ => ‘AND’,
// ‘terms’ => $terms)//array(75,72))
// ))
// );
// //print_r($posts);
// foreach ($posts as $key => $value) {
// $meta = get_post_meta($value->ID);
// $value->link = $meta[‘sdm_upload’][0];
// $value->thumb = $meta[‘sdm_upload_thumbnail’][0];
// }
$posts = get_posts(array(
‘post_type’ => ‘dlm_download’,
‘numberposts’ => $type,
‘tax_query’ => array(
array(
‘taxonomy’ => ‘dlm_download_category’,
‘field’ => ‘term_id’,
‘operator’ => ‘AND’,
‘terms’ => $terms
)
)
)
);
foreach ($posts as $key => $value) {
$sub_posts = get_posts(array(
‘post_parent’ => $value->ID,
‘post_type’ => ‘dlm_download_version’,
)
);
foreach ($sub_posts as $key => $value2) {
$meta = get_post_meta($value2->ID);
$value->link = trim($meta[‘_files’][0],'[“”]’);
}
$thumb_posts = get_posts(array(
‘post_parent’ => $value->ID,
‘post_type’ => ‘attachment’,
)
);
$value->thumb=””;
foreach ($thumb_posts as $key => $value3) {
$value->thumb = $value3->guid;
}
$cats = $wpdb->get_row( “SELECT GROUP_CONCAT(term_taxonomy_id) as cat FROM samrh_term_relationships WHERE object_id = “.$value->ID );
$value->cats=explode(“,”, $cats->cat);
}
$response[‘success’] = 1;
$response[‘message’] = $posts;
echo json_encode($response);
}
?>
Test
<?php
ini_set(‘display_errors’, 1);
ini_set(‘display_startup_errors’, 1);
error_reporting(E_ALL);
global $wpdb;
$terms = isset($_POST[‘terms’])?$_POST[‘terms’]:array(75);
if (empty($terms)){
$response[‘success’] = 0;
$response[‘message’] = “Terms Not recieved”;
echo json_encode($response);
} else{
require_once($_SERVER[‘DOCUMENT_ROOT’].’/demo/wp-load.php’);
$posts = get_posts(array(
‘post_type’ => ‘dlm_download’,
‘tax_query’ => array(
array(
‘taxonomy’ => ‘dlm_download_category’,
‘field’ => ‘term_id’,
‘operator’ => ‘IN’,
‘terms’ => array(106)
)
)
)
);
foreach ($posts as $key => $value) {
$sub_posts = get_posts(array(
‘post_parent’ => $value->ID,
‘post_type’ => ‘dlm_download_version’,
)
);
foreach ($sub_posts as $key => $value2) {
$meta = get_post_meta($value2->ID);
$value->link = trim($meta[‘_files’][0],'[“”]’);
}
$thumb_posts = get_posts(array(
‘post_parent’ => $value->ID,
‘post_type’ => ‘attachment’,
)
);
$value->thumb=””;
foreach ($thumb_posts as $key => $value3) {
$value->thumb = $value3->guid;
}
$cats = $wpdb->get_row( “SELECT GROUP_CONCAT(term_taxonomy_id) as cat FROM samrh_term_relationships WHERE object_id = “.$value->ID );
$value->cats=explode(“,”, $cats->cat);
}
$response[‘success’] = 1;
$response[‘message’] = $posts;
echo json_encode($response);
}
?>