Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter('get_previous_post_join','sql_get_adjacent_post_join');
- add_filter('get_next_post_join','sql_get_adjacent_post_join');
- add_filter('get_previous_post_sort','sql_get_adjacent_post_sort');
- add_filter('get_next_post_sort','sql_get_adjacent_post_sort');
- add_filter( 'get_previous_post_where', 'filter_private_future_nextprevious_links' );
- add_filter( 'get_next_post_where', 'filter_private_future_nextprevious_links' );
- function sql_get_adjacent_post_join($join) {
- global $post, $wpdb;
- if('story-images' == get_post_type() || 'editorials' == get_post_type()) {
- return $join . " INNER JOIN $wpdb->postmeta AS m ON p.ID = m.post_id";
- }
- }
- function filter_private_future_nextprevious_links($where) {
- global $post;
- //check for selected editorial and get ID to pass into $where
- if('story-images' == get_post_type()) {
- if(get_field('editorial')) {
- foreach(get_field('editorial') as $post_object):
- $editorial_id = $post_object->ID;
- endforeach;
- }
- return $where . " AND m.meta_key = 'editorial' AND m.meta_value = $editorial_id";
- }
- //check for selected editorial and get ID to pass into $where
- if('editorials' == get_post_type()) {
- if(get_field('author') == 'Randy') {
- $this_id = $post->ID;
- $stories = get_field('stories', 863);
- $story_ids = array();
- foreach($stories as $story) {
- $story_ids[] = $story->ID;
- }
- $ids_for_where = implode(',', $story_ids);
- return $where . " AND m.meta_key = 'author' AND m.meta_value = 'Randy' AND p.ID IN ($ids_for_where)";
- } elseif(get_field('author') == 'Melissa') {
- $this_id = $post->ID;
- $stories = get_field('stories', 881);
- $story_ids = array();
- foreach($stories as $story) {
- $story_ids[] = $story->ID;
- }
- $ids_for_where = implode(',', $story_ids);
- return $where . " AND m.meta_key = 'author' AND m.meta_value = 'Melissa' AND p.ID IN ($ids_for_where)";
- }
- }
- }
- function sql_get_adjacent_post_sort($sort) {
- global $post, $wpdb;
- $this_id = $post->ID;
- if('story-images' == get_post_type()) {
- if(($editorials = get_field('editorial'))) {
- $editorial = current($editorials);
- $editorial_id = $editorial->ID;
- $editorial_images = get_field('editorial-images', $editorial_id);
- $editorial_image_ids = array();
- foreach($editorial_images as $editorial_image) {
- $editorial_image_ids[] = $editorial_image->ID;
- }
- if(!empty($editorial_image_ids)) {
- $ids_for_sort = implode(',', $editorial_image_ids);
- echo $ids_for_sort;
- $sort = "ORDER BY FIELD(p.ID, {$ids_for_sort})";
- }
- }
- }
- echo $sort;
- return $sort;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement