FacetWP – include post IDs in the AJAX response

mgibbs189

{{gist file=”front.js” lang=”javascript”}}
(function($) {
$(document).on(‘facetwp-loaded’, function() {
var post_ids = FWP.settings.post_ids;
// TODO: store post IDs into a cookie
});
})(jQuery);
{{/gist}}{{gist file=”functions.php” lang=”php”}}
<?php

function fwp_ajax_return_post_ids( $output, $params ) {
$output[‘settings’][‘post_ids’] = FWP()->facet->query->post__in;
return $output;
}
add_filter( ‘facetwp_render_output’, ‘fwp_ajax_return_post_ids’, 10, 2 );
{{/gist}}{{gist file=”single.php” lang=”php”}}
<?php

// 1. Check for cookie
$post_ids = isset( $_COOKIE[‘yourcookie’] ) ? $_COOKIE[‘yourcookie’] : array();

// 2. If cookie exists, find the current post ID in the array

// 3. Get the element before, and after the current post ID. Then run these IDs through get_permalink to get their URLs
{{/gist}}