I found a question about magazine style front pages that queries always only 1 post (or custom_post_types, etc.) from a whole load of different categories, tags or custom taxonomies. I thought about this for a while and came with something like this as a start.
function pre_saved_posts() {
if (
! is_admin()
OR ! current_user_can( 'edit_posts' )
)
return;
global $post;
// Option-Name
$opt_name = 'theme_post_ids';
// get data from DB
$db_option_value = get_option( $opt_name );
// If there's nothing in the DB, create an array, else add the ID to the array of post_IDs
empty( $db_option_value ) ? $post_ids = array( $post->ID ) : $post_ids .= $post->ID;
// get posts
$posts = get_posts( array( 'include' => $post_ids ) );
// DB-Option @Option-Table updaten or add
empty( $db_option_value ) ? add_option( $opt_name, $posts ) : update_option( $opt_name, $posts );
}
// Do it when a post is updated
add_action( 'save_post', 'pre_saved_posts', 20 );
Would be displayed like this:
$some_posts = get_option( 'theme_post_ids' );
foreach ( $some_posts as $post )
{
// possible for ex.: $post->ID, $post->post_content, $post->post_title, etc.
}
It's not tested and only an example, but maybe there's someone interested in extending this. I still question myself how much sense it makes, but i could imagine that there's one large multidimensional array that contains subarrays for different requests ex.
$some_posts = get_option( 'theme_post_ids' ); $home_posts = $someposts['home'];
If this would be stored in a global $var, maybe there could be some performance increase.
Ideas/Suggestions/Whatever?