Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
1.3 kB
10
Indexable
Never
/* REORDER POST NAV */
add_filter( 'get_next_post_where', 'lbardugo_adjacent_post_where' );
add_filter( 'get_previous_post_where', 'lbardugo_adjacent_post_where' );
/**
 * Overrides the post navigation to sort by menu order.
 *
 * @since 1.0.0
 *
 * @param $sql
 * @return mixed
 */
function lbardugo_adjacent_post_where($sql) {
  
  // Get out now if this isn't the query we want to filter
	if ( !is_main_query() || !is_singular() )
		return $sql;
	
	$the_post = get_post( get_the_ID() );
	$patterns = array();
	$patterns[] = '/post_date/';
	$patterns[] = '/\'[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}\'/';
	$replacements = array();
	$replacements[] = 'menu_order';
	$replacements[] = $the_post->menu_order;
	return preg_replace( $patterns, $replacements, $sql );
  
}

add_filter( 'get_next_post_sort', 'lbardugo_adjacent_post_sort' );
add_filter( 'get_previous_post_sort', 'lbardugo_adjacent_post_sort' );
/**
 * Overrides the post navigation to sort by menu order.
 *
 * @since 1.0.0
 *
 * @param $sql
 * @return mixed
 */
function lbardugo_adjacent_post_sort($sql) {
  
  // Get out now if this isn't the query we want to filter
	if ( !is_main_query() || !is_singular() )
		return $sql;
	
	$pattern = '/post_date/';
	$replacement = 'menu_order';
	return preg_replace( $pattern, $replacement, $sql );
  
}
Leave a Comment