Wordpress get_post_meta() array data cannot pass via backbone js











up vote
1
down vote

favorite












I have add a custom field to get selected IDs using Metabox.



    array(

'name' => __('Select projects', 'x2-backend'),

'id' => "{$prefix}similar_projects_list",

'type' => 'select_advanced',

'multiple' => true,

'options' => $pages_clients_list,

),



$args_clients = array(
'sort_order' => 'ASC',
'sort_column' => 'post_title',
'hierarchical' => 1,
'exclude' => $post_id,
'include' => '',
'meta_key' => '',
'meta_value' => '',
'authors' => '',
'child_of' => 0,
'parent' => -1,
'exclude_tree' => '',
'number' => '',
'offset' => 0,
'post_type' => 'room',
'post_status' => 'publish'
);

$pages_clients = get_pages($args_clients);
foreach ($pages_clients as $pages_client) {
if ($pages_client->ID !`enter code here`= '') {
$pages_clients_list[$pages_client->ID] = $pages_client->post_title;
}
}


My view is using backbone js. below is my code.



<script type="text/template" id="villashome-item-tpl-similar-projects">
<article class="promosgrid-el withborder with-buttons <?php echo ($sproject->room_bookonlinelink == '' && $sproject->room_enquiryform != 1 ? 'buttonNotActive' : ''); ?> with-grdient with-overlay">

<h3 class="title">
<a title="<%= md.name %>" href="<%= md.permalink %>"><%= md.name %></a>
</h3>
<h4 class="subtitle"><%= md.secondtext_title %></h4>
<div class="img-cont">
<div class="img-hover-overlay">
<a title="<%= md.seo_title %>" href="<%= md.permalink %>">
<img itemprop="image" alt="" src="<%= md.image_thumb_desktop %>" />
</a>
<a title="<%= md.seo_title %>" href="<%= md.permalink %>">
<div class="img-hover-text"><?php echo ___('+ more info', 'x2-frontend', 'villa_collection_more_info'); ?></div>
</a>
</div>
</div>

</article>
</script>


The loadmore button code is here



<?php 
$IDs = get_post_meta( get_the_id() , 'ct_mb_similar_projects_list', false );
$total_rooms = x2_get_similar_projects($IDs);
// var_dump(count($total_rooms));
if ( count($total_rooms)>3 ) { ?>
<div id="villas-load-more-div" class="spacer-el loadmore-wrp">
<a id="villas-load-more" class="btns load-more btn-stroke scrollto-action loadmore-gallery-action" href="#"><?php echo ___('Load more X2 Clients', 'x2-frontend', 'gallery_loadmorephotos_btn'); ?></a>
</div>
<?php } ?>


This button call to the following code in my script.js file



if($('.homepage-villas-similar-projects').length>0){
// $.stellar('refresh');
$('.homepage-villas-similar-projects').easyLoad2({
'tpl_selector':'#villashome-item-tpl-similar-projects',
'loadstep': 3,
'getDataType':'getsimilarprojects',
'offset': 3,
});
}


From this script call getsimilarprojects function in my plugin.js via easyload2 function.



easyload2 function is on my plugin.js



    $.fn.easyLoad2 = function (options) {
var el = $(this);
var settings = $.extend({
'tpl_selector': '#blogpost-item-tpl',
'loadstep': 4,
'loadbtn': '.load-more',
'getDataType': 'getposts',
'offset': 0
}, options);
var el_ = $(this);
var jsonurl_ = directory_uri;
var Model = Backbone.Model.extend();
var Collection = Backbone.Collection.extend({
model: Model,
url: jsonurl_
});
var View = Backbone.View.extend({
el: el_,
initialize: function () {
var self = this;
_.each(this.model, function (v, i, l) {
this.template = _.template($(settings.tpl_selector).html(), {md: v});
var d = $(this.template);
self.$el.append(d);
}); $.stellar('refresh');
}
});
var func = {
countData: (settings.offset > 0 ? settings.offset : 0),
myData: '',
step: settings.loadstep,
loadaction: true,
init: function () {
var self = this;
self.scrollTriggers();
if (settings.offset == 0) {
self.data();
}
$('body').on('loadmoredata', function () {
self.data();
});
},
scrollTriggers: function () {
if (this.loadaction === false) {
return;
}
if ($(settings.loadbtn).length === 0) {
$(window).on("scroll", function () {
if (this.loadaction === true) {
var scrollHeight = $(document).height();
var scrollPosition = $(window).height() + $(window).scrollTop();
if ((scrollHeight - scrollPosition) / scrollHeight === 0) {
$('body').trigger('loadmoredata');
}
}
});
} else {
$(settings.loadbtn).on('click', function (e) {
e.preventDefault();
$('body').trigger('loadmoredata');
});
}
},
setCountData: function () {
this.countData += this.myData.length;
},
data: function () {
var self = this;
var myCollection = new Collection();
myCollection.url = jsonurl_ + '?' + settings.getDataType + '=' + self.countData + '&items=' + self.step;
// console.log(myCollection.url);
myCollection.fetch({success: function () {
self.myData = myCollection.toJSON();
self.setCountData();
self.tpl();
}});
},
tpl: function () {
var self = this;
if (self.myData.length !== self.step) {
self.step = self.myData.length;
}
if (self.myData.length === 0) {
self.loadaction = false;
return;
}
if (self.myData[0].count === void 0) {
} else {
if (self.countData >= self.myData[0].count) {
$(settings.loadbtn).hide();
}
}
var myView = new View({model: self.myData});
var scrolltoElement = el_.find('li').eq(self.countData - self.step);
if (self.countData - self.step > 0) {
setTimeout(function () {
$('body').stop(true, true).scrollTo(scrolltoElement, 700, {axis: 'y', offset: {top: 0}, onAfter: function () {
}});
}, 1000);
}
}
};
func.init();
};


My getsimilarprojects() is here



if ( isset( $_REQUEST['getsimilarprojects'] ) ) {
add_action( 'wp_loaded', 'getsimilarprojects');
}
function getsimilarprojects() {
header('Content-type: application/json');
$offset = $_REQUEST['getsimilarprojects'];
$items = $_REQUEST['items'];
$IDs = get_post_meta( get_the_id() , 'ct_mb_similar_projects_list', false );
$args_rooms_ = array(
'posts_per_page' => -1,
'post_type' => 'room',
'posts_per_page' => ($items == 0)? -1: $items,
'offset' => ($offset == 0) ? 0: $offset,
'orderby' => 'menu_order',
'order' => 'ASC',
'post__in' => $IDs,
);
$rooms_query_ = new WP_Query($args_rooms_);
$ar = array();
$i = 0;
while ($rooms_query_->have_posts()) {
$rooms_query_->the_post();
$x2postmeta_room = setX2Globals(get_the_ID());
$ar[$i]['id'] = get_the_ID();
$ar[$i]['name'] = get_the_title();
$ar[$i]['permalink'] = get_permalink();
$ar[$i]['homepageactive'] = ( $x2postmeta_room->room_homepage_dropdown == 1 ? 1 : 0 );
$ar[$i]['order'] = $x2postmeta_room->room_meta_order;
$ar[$i]['price'] = $x2postmeta_room->room_price;
$ar[$i]['feature_title'] = ( $x2postmeta_room->room_feature_title != '' ? $x2postmeta_room->room_feature_title : get_the_title() );
$ar[$i]['feature_status'] = ( $x2postmeta_room->room_feature_status == 1 ? true : false );
$ar[$i]['image_thumb_desktop'] = getFeaturedImage(get_post_thumbnail_id(), 'x2_thumb_374x270', 'x2_thumb_374x270');
$ar[$i]['seo_title_btn'] = $x2postmeta_room->room_seo_title;
$ar[$i]['count'] = $rooms_query_->found_posts;
$i++;
}
wp_reset_query();
echo json_encode($ar);
die();
}


The problem is I cannot get the $IDs value for 'post__in'.
In this section does not get get_the_id(); value. Why is it? & How can I solve this?










share|improve this question






















  • Please go read How to Ask. IMHO this is way too much code, and too little explanation of what the actual problem is.
    – misorude
    Nov 9 at 13:09















up vote
1
down vote

favorite












I have add a custom field to get selected IDs using Metabox.



    array(

'name' => __('Select projects', 'x2-backend'),

'id' => "{$prefix}similar_projects_list",

'type' => 'select_advanced',

'multiple' => true,

'options' => $pages_clients_list,

),



$args_clients = array(
'sort_order' => 'ASC',
'sort_column' => 'post_title',
'hierarchical' => 1,
'exclude' => $post_id,
'include' => '',
'meta_key' => '',
'meta_value' => '',
'authors' => '',
'child_of' => 0,
'parent' => -1,
'exclude_tree' => '',
'number' => '',
'offset' => 0,
'post_type' => 'room',
'post_status' => 'publish'
);

$pages_clients = get_pages($args_clients);
foreach ($pages_clients as $pages_client) {
if ($pages_client->ID !`enter code here`= '') {
$pages_clients_list[$pages_client->ID] = $pages_client->post_title;
}
}


My view is using backbone js. below is my code.



<script type="text/template" id="villashome-item-tpl-similar-projects">
<article class="promosgrid-el withborder with-buttons <?php echo ($sproject->room_bookonlinelink == '' && $sproject->room_enquiryform != 1 ? 'buttonNotActive' : ''); ?> with-grdient with-overlay">

<h3 class="title">
<a title="<%= md.name %>" href="<%= md.permalink %>"><%= md.name %></a>
</h3>
<h4 class="subtitle"><%= md.secondtext_title %></h4>
<div class="img-cont">
<div class="img-hover-overlay">
<a title="<%= md.seo_title %>" href="<%= md.permalink %>">
<img itemprop="image" alt="" src="<%= md.image_thumb_desktop %>" />
</a>
<a title="<%= md.seo_title %>" href="<%= md.permalink %>">
<div class="img-hover-text"><?php echo ___('+ more info', 'x2-frontend', 'villa_collection_more_info'); ?></div>
</a>
</div>
</div>

</article>
</script>


The loadmore button code is here



<?php 
$IDs = get_post_meta( get_the_id() , 'ct_mb_similar_projects_list', false );
$total_rooms = x2_get_similar_projects($IDs);
// var_dump(count($total_rooms));
if ( count($total_rooms)>3 ) { ?>
<div id="villas-load-more-div" class="spacer-el loadmore-wrp">
<a id="villas-load-more" class="btns load-more btn-stroke scrollto-action loadmore-gallery-action" href="#"><?php echo ___('Load more X2 Clients', 'x2-frontend', 'gallery_loadmorephotos_btn'); ?></a>
</div>
<?php } ?>


This button call to the following code in my script.js file



if($('.homepage-villas-similar-projects').length>0){
// $.stellar('refresh');
$('.homepage-villas-similar-projects').easyLoad2({
'tpl_selector':'#villashome-item-tpl-similar-projects',
'loadstep': 3,
'getDataType':'getsimilarprojects',
'offset': 3,
});
}


From this script call getsimilarprojects function in my plugin.js via easyload2 function.



easyload2 function is on my plugin.js



    $.fn.easyLoad2 = function (options) {
var el = $(this);
var settings = $.extend({
'tpl_selector': '#blogpost-item-tpl',
'loadstep': 4,
'loadbtn': '.load-more',
'getDataType': 'getposts',
'offset': 0
}, options);
var el_ = $(this);
var jsonurl_ = directory_uri;
var Model = Backbone.Model.extend();
var Collection = Backbone.Collection.extend({
model: Model,
url: jsonurl_
});
var View = Backbone.View.extend({
el: el_,
initialize: function () {
var self = this;
_.each(this.model, function (v, i, l) {
this.template = _.template($(settings.tpl_selector).html(), {md: v});
var d = $(this.template);
self.$el.append(d);
}); $.stellar('refresh');
}
});
var func = {
countData: (settings.offset > 0 ? settings.offset : 0),
myData: '',
step: settings.loadstep,
loadaction: true,
init: function () {
var self = this;
self.scrollTriggers();
if (settings.offset == 0) {
self.data();
}
$('body').on('loadmoredata', function () {
self.data();
});
},
scrollTriggers: function () {
if (this.loadaction === false) {
return;
}
if ($(settings.loadbtn).length === 0) {
$(window).on("scroll", function () {
if (this.loadaction === true) {
var scrollHeight = $(document).height();
var scrollPosition = $(window).height() + $(window).scrollTop();
if ((scrollHeight - scrollPosition) / scrollHeight === 0) {
$('body').trigger('loadmoredata');
}
}
});
} else {
$(settings.loadbtn).on('click', function (e) {
e.preventDefault();
$('body').trigger('loadmoredata');
});
}
},
setCountData: function () {
this.countData += this.myData.length;
},
data: function () {
var self = this;
var myCollection = new Collection();
myCollection.url = jsonurl_ + '?' + settings.getDataType + '=' + self.countData + '&items=' + self.step;
// console.log(myCollection.url);
myCollection.fetch({success: function () {
self.myData = myCollection.toJSON();
self.setCountData();
self.tpl();
}});
},
tpl: function () {
var self = this;
if (self.myData.length !== self.step) {
self.step = self.myData.length;
}
if (self.myData.length === 0) {
self.loadaction = false;
return;
}
if (self.myData[0].count === void 0) {
} else {
if (self.countData >= self.myData[0].count) {
$(settings.loadbtn).hide();
}
}
var myView = new View({model: self.myData});
var scrolltoElement = el_.find('li').eq(self.countData - self.step);
if (self.countData - self.step > 0) {
setTimeout(function () {
$('body').stop(true, true).scrollTo(scrolltoElement, 700, {axis: 'y', offset: {top: 0}, onAfter: function () {
}});
}, 1000);
}
}
};
func.init();
};


My getsimilarprojects() is here



if ( isset( $_REQUEST['getsimilarprojects'] ) ) {
add_action( 'wp_loaded', 'getsimilarprojects');
}
function getsimilarprojects() {
header('Content-type: application/json');
$offset = $_REQUEST['getsimilarprojects'];
$items = $_REQUEST['items'];
$IDs = get_post_meta( get_the_id() , 'ct_mb_similar_projects_list', false );
$args_rooms_ = array(
'posts_per_page' => -1,
'post_type' => 'room',
'posts_per_page' => ($items == 0)? -1: $items,
'offset' => ($offset == 0) ? 0: $offset,
'orderby' => 'menu_order',
'order' => 'ASC',
'post__in' => $IDs,
);
$rooms_query_ = new WP_Query($args_rooms_);
$ar = array();
$i = 0;
while ($rooms_query_->have_posts()) {
$rooms_query_->the_post();
$x2postmeta_room = setX2Globals(get_the_ID());
$ar[$i]['id'] = get_the_ID();
$ar[$i]['name'] = get_the_title();
$ar[$i]['permalink'] = get_permalink();
$ar[$i]['homepageactive'] = ( $x2postmeta_room->room_homepage_dropdown == 1 ? 1 : 0 );
$ar[$i]['order'] = $x2postmeta_room->room_meta_order;
$ar[$i]['price'] = $x2postmeta_room->room_price;
$ar[$i]['feature_title'] = ( $x2postmeta_room->room_feature_title != '' ? $x2postmeta_room->room_feature_title : get_the_title() );
$ar[$i]['feature_status'] = ( $x2postmeta_room->room_feature_status == 1 ? true : false );
$ar[$i]['image_thumb_desktop'] = getFeaturedImage(get_post_thumbnail_id(), 'x2_thumb_374x270', 'x2_thumb_374x270');
$ar[$i]['seo_title_btn'] = $x2postmeta_room->room_seo_title;
$ar[$i]['count'] = $rooms_query_->found_posts;
$i++;
}
wp_reset_query();
echo json_encode($ar);
die();
}


The problem is I cannot get the $IDs value for 'post__in'.
In this section does not get get_the_id(); value. Why is it? & How can I solve this?










share|improve this question






















  • Please go read How to Ask. IMHO this is way too much code, and too little explanation of what the actual problem is.
    – misorude
    Nov 9 at 13:09













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I have add a custom field to get selected IDs using Metabox.



    array(

'name' => __('Select projects', 'x2-backend'),

'id' => "{$prefix}similar_projects_list",

'type' => 'select_advanced',

'multiple' => true,

'options' => $pages_clients_list,

),



$args_clients = array(
'sort_order' => 'ASC',
'sort_column' => 'post_title',
'hierarchical' => 1,
'exclude' => $post_id,
'include' => '',
'meta_key' => '',
'meta_value' => '',
'authors' => '',
'child_of' => 0,
'parent' => -1,
'exclude_tree' => '',
'number' => '',
'offset' => 0,
'post_type' => 'room',
'post_status' => 'publish'
);

$pages_clients = get_pages($args_clients);
foreach ($pages_clients as $pages_client) {
if ($pages_client->ID !`enter code here`= '') {
$pages_clients_list[$pages_client->ID] = $pages_client->post_title;
}
}


My view is using backbone js. below is my code.



<script type="text/template" id="villashome-item-tpl-similar-projects">
<article class="promosgrid-el withborder with-buttons <?php echo ($sproject->room_bookonlinelink == '' && $sproject->room_enquiryform != 1 ? 'buttonNotActive' : ''); ?> with-grdient with-overlay">

<h3 class="title">
<a title="<%= md.name %>" href="<%= md.permalink %>"><%= md.name %></a>
</h3>
<h4 class="subtitle"><%= md.secondtext_title %></h4>
<div class="img-cont">
<div class="img-hover-overlay">
<a title="<%= md.seo_title %>" href="<%= md.permalink %>">
<img itemprop="image" alt="" src="<%= md.image_thumb_desktop %>" />
</a>
<a title="<%= md.seo_title %>" href="<%= md.permalink %>">
<div class="img-hover-text"><?php echo ___('+ more info', 'x2-frontend', 'villa_collection_more_info'); ?></div>
</a>
</div>
</div>

</article>
</script>


The loadmore button code is here



<?php 
$IDs = get_post_meta( get_the_id() , 'ct_mb_similar_projects_list', false );
$total_rooms = x2_get_similar_projects($IDs);
// var_dump(count($total_rooms));
if ( count($total_rooms)>3 ) { ?>
<div id="villas-load-more-div" class="spacer-el loadmore-wrp">
<a id="villas-load-more" class="btns load-more btn-stroke scrollto-action loadmore-gallery-action" href="#"><?php echo ___('Load more X2 Clients', 'x2-frontend', 'gallery_loadmorephotos_btn'); ?></a>
</div>
<?php } ?>


This button call to the following code in my script.js file



if($('.homepage-villas-similar-projects').length>0){
// $.stellar('refresh');
$('.homepage-villas-similar-projects').easyLoad2({
'tpl_selector':'#villashome-item-tpl-similar-projects',
'loadstep': 3,
'getDataType':'getsimilarprojects',
'offset': 3,
});
}


From this script call getsimilarprojects function in my plugin.js via easyload2 function.



easyload2 function is on my plugin.js



    $.fn.easyLoad2 = function (options) {
var el = $(this);
var settings = $.extend({
'tpl_selector': '#blogpost-item-tpl',
'loadstep': 4,
'loadbtn': '.load-more',
'getDataType': 'getposts',
'offset': 0
}, options);
var el_ = $(this);
var jsonurl_ = directory_uri;
var Model = Backbone.Model.extend();
var Collection = Backbone.Collection.extend({
model: Model,
url: jsonurl_
});
var View = Backbone.View.extend({
el: el_,
initialize: function () {
var self = this;
_.each(this.model, function (v, i, l) {
this.template = _.template($(settings.tpl_selector).html(), {md: v});
var d = $(this.template);
self.$el.append(d);
}); $.stellar('refresh');
}
});
var func = {
countData: (settings.offset > 0 ? settings.offset : 0),
myData: '',
step: settings.loadstep,
loadaction: true,
init: function () {
var self = this;
self.scrollTriggers();
if (settings.offset == 0) {
self.data();
}
$('body').on('loadmoredata', function () {
self.data();
});
},
scrollTriggers: function () {
if (this.loadaction === false) {
return;
}
if ($(settings.loadbtn).length === 0) {
$(window).on("scroll", function () {
if (this.loadaction === true) {
var scrollHeight = $(document).height();
var scrollPosition = $(window).height() + $(window).scrollTop();
if ((scrollHeight - scrollPosition) / scrollHeight === 0) {
$('body').trigger('loadmoredata');
}
}
});
} else {
$(settings.loadbtn).on('click', function (e) {
e.preventDefault();
$('body').trigger('loadmoredata');
});
}
},
setCountData: function () {
this.countData += this.myData.length;
},
data: function () {
var self = this;
var myCollection = new Collection();
myCollection.url = jsonurl_ + '?' + settings.getDataType + '=' + self.countData + '&items=' + self.step;
// console.log(myCollection.url);
myCollection.fetch({success: function () {
self.myData = myCollection.toJSON();
self.setCountData();
self.tpl();
}});
},
tpl: function () {
var self = this;
if (self.myData.length !== self.step) {
self.step = self.myData.length;
}
if (self.myData.length === 0) {
self.loadaction = false;
return;
}
if (self.myData[0].count === void 0) {
} else {
if (self.countData >= self.myData[0].count) {
$(settings.loadbtn).hide();
}
}
var myView = new View({model: self.myData});
var scrolltoElement = el_.find('li').eq(self.countData - self.step);
if (self.countData - self.step > 0) {
setTimeout(function () {
$('body').stop(true, true).scrollTo(scrolltoElement, 700, {axis: 'y', offset: {top: 0}, onAfter: function () {
}});
}, 1000);
}
}
};
func.init();
};


My getsimilarprojects() is here



if ( isset( $_REQUEST['getsimilarprojects'] ) ) {
add_action( 'wp_loaded', 'getsimilarprojects');
}
function getsimilarprojects() {
header('Content-type: application/json');
$offset = $_REQUEST['getsimilarprojects'];
$items = $_REQUEST['items'];
$IDs = get_post_meta( get_the_id() , 'ct_mb_similar_projects_list', false );
$args_rooms_ = array(
'posts_per_page' => -1,
'post_type' => 'room',
'posts_per_page' => ($items == 0)? -1: $items,
'offset' => ($offset == 0) ? 0: $offset,
'orderby' => 'menu_order',
'order' => 'ASC',
'post__in' => $IDs,
);
$rooms_query_ = new WP_Query($args_rooms_);
$ar = array();
$i = 0;
while ($rooms_query_->have_posts()) {
$rooms_query_->the_post();
$x2postmeta_room = setX2Globals(get_the_ID());
$ar[$i]['id'] = get_the_ID();
$ar[$i]['name'] = get_the_title();
$ar[$i]['permalink'] = get_permalink();
$ar[$i]['homepageactive'] = ( $x2postmeta_room->room_homepage_dropdown == 1 ? 1 : 0 );
$ar[$i]['order'] = $x2postmeta_room->room_meta_order;
$ar[$i]['price'] = $x2postmeta_room->room_price;
$ar[$i]['feature_title'] = ( $x2postmeta_room->room_feature_title != '' ? $x2postmeta_room->room_feature_title : get_the_title() );
$ar[$i]['feature_status'] = ( $x2postmeta_room->room_feature_status == 1 ? true : false );
$ar[$i]['image_thumb_desktop'] = getFeaturedImage(get_post_thumbnail_id(), 'x2_thumb_374x270', 'x2_thumb_374x270');
$ar[$i]['seo_title_btn'] = $x2postmeta_room->room_seo_title;
$ar[$i]['count'] = $rooms_query_->found_posts;
$i++;
}
wp_reset_query();
echo json_encode($ar);
die();
}


The problem is I cannot get the $IDs value for 'post__in'.
In this section does not get get_the_id(); value. Why is it? & How can I solve this?










share|improve this question













I have add a custom field to get selected IDs using Metabox.



    array(

'name' => __('Select projects', 'x2-backend'),

'id' => "{$prefix}similar_projects_list",

'type' => 'select_advanced',

'multiple' => true,

'options' => $pages_clients_list,

),



$args_clients = array(
'sort_order' => 'ASC',
'sort_column' => 'post_title',
'hierarchical' => 1,
'exclude' => $post_id,
'include' => '',
'meta_key' => '',
'meta_value' => '',
'authors' => '',
'child_of' => 0,
'parent' => -1,
'exclude_tree' => '',
'number' => '',
'offset' => 0,
'post_type' => 'room',
'post_status' => 'publish'
);

$pages_clients = get_pages($args_clients);
foreach ($pages_clients as $pages_client) {
if ($pages_client->ID !`enter code here`= '') {
$pages_clients_list[$pages_client->ID] = $pages_client->post_title;
}
}


My view is using backbone js. below is my code.



<script type="text/template" id="villashome-item-tpl-similar-projects">
<article class="promosgrid-el withborder with-buttons <?php echo ($sproject->room_bookonlinelink == '' && $sproject->room_enquiryform != 1 ? 'buttonNotActive' : ''); ?> with-grdient with-overlay">

<h3 class="title">
<a title="<%= md.name %>" href="<%= md.permalink %>"><%= md.name %></a>
</h3>
<h4 class="subtitle"><%= md.secondtext_title %></h4>
<div class="img-cont">
<div class="img-hover-overlay">
<a title="<%= md.seo_title %>" href="<%= md.permalink %>">
<img itemprop="image" alt="" src="<%= md.image_thumb_desktop %>" />
</a>
<a title="<%= md.seo_title %>" href="<%= md.permalink %>">
<div class="img-hover-text"><?php echo ___('+ more info', 'x2-frontend', 'villa_collection_more_info'); ?></div>
</a>
</div>
</div>

</article>
</script>


The loadmore button code is here



<?php 
$IDs = get_post_meta( get_the_id() , 'ct_mb_similar_projects_list', false );
$total_rooms = x2_get_similar_projects($IDs);
// var_dump(count($total_rooms));
if ( count($total_rooms)>3 ) { ?>
<div id="villas-load-more-div" class="spacer-el loadmore-wrp">
<a id="villas-load-more" class="btns load-more btn-stroke scrollto-action loadmore-gallery-action" href="#"><?php echo ___('Load more X2 Clients', 'x2-frontend', 'gallery_loadmorephotos_btn'); ?></a>
</div>
<?php } ?>


This button call to the following code in my script.js file



if($('.homepage-villas-similar-projects').length>0){
// $.stellar('refresh');
$('.homepage-villas-similar-projects').easyLoad2({
'tpl_selector':'#villashome-item-tpl-similar-projects',
'loadstep': 3,
'getDataType':'getsimilarprojects',
'offset': 3,
});
}


From this script call getsimilarprojects function in my plugin.js via easyload2 function.



easyload2 function is on my plugin.js



    $.fn.easyLoad2 = function (options) {
var el = $(this);
var settings = $.extend({
'tpl_selector': '#blogpost-item-tpl',
'loadstep': 4,
'loadbtn': '.load-more',
'getDataType': 'getposts',
'offset': 0
}, options);
var el_ = $(this);
var jsonurl_ = directory_uri;
var Model = Backbone.Model.extend();
var Collection = Backbone.Collection.extend({
model: Model,
url: jsonurl_
});
var View = Backbone.View.extend({
el: el_,
initialize: function () {
var self = this;
_.each(this.model, function (v, i, l) {
this.template = _.template($(settings.tpl_selector).html(), {md: v});
var d = $(this.template);
self.$el.append(d);
}); $.stellar('refresh');
}
});
var func = {
countData: (settings.offset > 0 ? settings.offset : 0),
myData: '',
step: settings.loadstep,
loadaction: true,
init: function () {
var self = this;
self.scrollTriggers();
if (settings.offset == 0) {
self.data();
}
$('body').on('loadmoredata', function () {
self.data();
});
},
scrollTriggers: function () {
if (this.loadaction === false) {
return;
}
if ($(settings.loadbtn).length === 0) {
$(window).on("scroll", function () {
if (this.loadaction === true) {
var scrollHeight = $(document).height();
var scrollPosition = $(window).height() + $(window).scrollTop();
if ((scrollHeight - scrollPosition) / scrollHeight === 0) {
$('body').trigger('loadmoredata');
}
}
});
} else {
$(settings.loadbtn).on('click', function (e) {
e.preventDefault();
$('body').trigger('loadmoredata');
});
}
},
setCountData: function () {
this.countData += this.myData.length;
},
data: function () {
var self = this;
var myCollection = new Collection();
myCollection.url = jsonurl_ + '?' + settings.getDataType + '=' + self.countData + '&items=' + self.step;
// console.log(myCollection.url);
myCollection.fetch({success: function () {
self.myData = myCollection.toJSON();
self.setCountData();
self.tpl();
}});
},
tpl: function () {
var self = this;
if (self.myData.length !== self.step) {
self.step = self.myData.length;
}
if (self.myData.length === 0) {
self.loadaction = false;
return;
}
if (self.myData[0].count === void 0) {
} else {
if (self.countData >= self.myData[0].count) {
$(settings.loadbtn).hide();
}
}
var myView = new View({model: self.myData});
var scrolltoElement = el_.find('li').eq(self.countData - self.step);
if (self.countData - self.step > 0) {
setTimeout(function () {
$('body').stop(true, true).scrollTo(scrolltoElement, 700, {axis: 'y', offset: {top: 0}, onAfter: function () {
}});
}, 1000);
}
}
};
func.init();
};


My getsimilarprojects() is here



if ( isset( $_REQUEST['getsimilarprojects'] ) ) {
add_action( 'wp_loaded', 'getsimilarprojects');
}
function getsimilarprojects() {
header('Content-type: application/json');
$offset = $_REQUEST['getsimilarprojects'];
$items = $_REQUEST['items'];
$IDs = get_post_meta( get_the_id() , 'ct_mb_similar_projects_list', false );
$args_rooms_ = array(
'posts_per_page' => -1,
'post_type' => 'room',
'posts_per_page' => ($items == 0)? -1: $items,
'offset' => ($offset == 0) ? 0: $offset,
'orderby' => 'menu_order',
'order' => 'ASC',
'post__in' => $IDs,
);
$rooms_query_ = new WP_Query($args_rooms_);
$ar = array();
$i = 0;
while ($rooms_query_->have_posts()) {
$rooms_query_->the_post();
$x2postmeta_room = setX2Globals(get_the_ID());
$ar[$i]['id'] = get_the_ID();
$ar[$i]['name'] = get_the_title();
$ar[$i]['permalink'] = get_permalink();
$ar[$i]['homepageactive'] = ( $x2postmeta_room->room_homepage_dropdown == 1 ? 1 : 0 );
$ar[$i]['order'] = $x2postmeta_room->room_meta_order;
$ar[$i]['price'] = $x2postmeta_room->room_price;
$ar[$i]['feature_title'] = ( $x2postmeta_room->room_feature_title != '' ? $x2postmeta_room->room_feature_title : get_the_title() );
$ar[$i]['feature_status'] = ( $x2postmeta_room->room_feature_status == 1 ? true : false );
$ar[$i]['image_thumb_desktop'] = getFeaturedImage(get_post_thumbnail_id(), 'x2_thumb_374x270', 'x2_thumb_374x270');
$ar[$i]['seo_title_btn'] = $x2postmeta_room->room_seo_title;
$ar[$i]['count'] = $rooms_query_->found_posts;
$i++;
}
wp_reset_query();
echo json_encode($ar);
die();
}


The problem is I cannot get the $IDs value for 'post__in'.
In this section does not get get_the_id(); value. Why is it? & How can I solve this?







javascript php wordpress






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 9 at 13:04









KokHanz

62




62












  • Please go read How to Ask. IMHO this is way too much code, and too little explanation of what the actual problem is.
    – misorude
    Nov 9 at 13:09


















  • Please go read How to Ask. IMHO this is way too much code, and too little explanation of what the actual problem is.
    – misorude
    Nov 9 at 13:09
















Please go read How to Ask. IMHO this is way too much code, and too little explanation of what the actual problem is.
– misorude
Nov 9 at 13:09




Please go read How to Ask. IMHO this is way too much code, and too little explanation of what the actual problem is.
– misorude
Nov 9 at 13:09

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53226258%2fwordpress-get-post-meta-array-data-cannot-pass-via-backbone-js%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53226258%2fwordpress-get-post-meta-array-data-cannot-pass-via-backbone-js%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Schultheiß

Android Play Services Check

Where to put API Key in Google Cloud Vision for PHP