Asking for assistance. I did the following hack:
Added the parameter “$for_category” to previous_post_link template tag, and to the casting of get_previous_post:
(don’t know how to use markup to highlight)
function previous_post_link($format=’« %link’, $link=’%title’, $in_same_cat = false, $excluded_categories = ”, $for_category) {
if ( is_attachment() )
$post = & get_post($GLOBALS[‘post’]->post_parent);
else
$post = get_previous_post($in_same_cat, $excluded_categories, $for_category);
if ( !$post )
return;
$title = apply_filters(‘the_title’, $post->post_title, $post);
$string = ‘ID).'”>’;
$link = str_replace(‘%title’, $title, $link);
$link = $pre . $string . $link . ‘‘;
$format = str_replace(‘%link’, $link, $format);
echo $format;
}
Then, added the same parameter to get_previous_post function, but defaulting it to what comes by default for $cat_array, within the if ($in_name_cat): ‘get_the_category($post->ID)’.
Then, replaced this original string with the parameter, so that the 5th value entered when casting prev_post_link, becomes the $cat_array:
function get_previous_post($in_same_cat = false, $excluded_categories = ”, $for_category = ‘get_the_category($post->ID)’) {
global $post, $wpdb;
if( !is_single() || is_attachment() )
return null;
$current_post_date = $post->post_date;
$join = ”;
if ( $in_same_cat ) {
$join = ” INNER JOIN $wpdb->post2cat ON $wpdb->posts.ID= $wpdb->post2cat.post_id “;
$cat_array = $for_category;
$join .= ‘ AND (category_id = ‘ . intval($cat_array[0]->cat_ID);
for ( $i = 1; $i < (count($cat_array)); $i++ ) {
$join .= ‘ OR category_id = ‘ . intval($cat_array[$i]->cat_ID);
}
$join .= ‘)’;
}
$sql_exclude_cats = ”;
if (!empty($excluded_categories)) {
### ronr hack ###
}
return @$wpdb->get_row(“SELECT ID, post_title FROM $wpdb->posts $join WHERE post_date < ‘$current_post_date’ AND post_status = ‘publish’ $sqlcat $sql_exclude_cats ORDER BY post_date DESC LIMIT 1”);
}
When I run the site with this hack, the page turns white whenever I cast it. Any suggestions?