function.php :
function prefix_ajax_activity_custom() {
$pageNumber = $_POST['pnumber'];
$activitlist = 'include='.$the_act_list.'&max=20&per_page=20&page=2';
if ( bp_has_activities( bp_ajax_querystring( 'activity' ) . $activitlist) ) :
while ( bp_activities() ) : bp_the_activity();
ob_start();
locate_template( array( 'buddypress/activity/entry.php' ), true, false );
$var .= ob_get_contents();
ob_end_clean();
endwhile;
endif;
wp_send_json_success($var);
}
add_action( 'wp_ajax_activity_custom', 'prefix_ajax_activity_custom' );
function prefix_ajax_activity_custom() {
$pageNumber = $_POST['pnumber'];
$activitlist = 'include='.$the_act_list.'&max=20&per_page=20&page=2';
if ( bp_has_activities( bp_ajax_querystring( 'activity' ) . $activitlist) ) :
while ( bp_activities() ) : bp_the_activity();
ob_start();
locate_template( array( 'buddypress/activity/entry.php' ), true, false );
$var .= ob_get_contents();
ob_end_clean();
endwhile;
endif;
wp_send_json_success($var);
}
add_action( 'wp_ajax_activity_custom', 'prefix_ajax_activity_custom' );
script.js:
function activitycustom( pnumber ) {
jQuery.post(
ajaxurl,
{
'action': 'activity_custom',
'pnumber': pnumber,
},
function(response){
var response = response.data;
$( ".ajax" ).append( response );
}
);
}
ref : https://stackoverflow.com/questions/5817726/wordpress-save-get-template-part-to-variable
No comments:
Post a Comment