我想你需要让它全球化。它可能看起来像:
add_action( \'pre_get_posts\', \'do_user_post_selection\' );
function do_user_post_selection( $query ) {
if( !is_home() || !is_user_logged_in() )
return;
if( isset( $query->query_vars[\'post_type\'] ) && ( \'nav_menu_item\' == $query->query_vars[\'post_type\'] ) )
return;
if( 1 < did_action(\'wp\') )
return;
global $current_user, $tax_selection;
$tax_selection = get_user_option( \'taxonomy_selection\', $current_user->ID );
if( empty( $tax_selection ) )
return;
if( isset( $tax_selection[\'categories\'] ) && ( is_array( $tax_selection[\'categories\'] ) ) && ( !empty( $tax_selection[\'categories\'] ) ) )
$query->set( \'category__in\', $tax_selection[\'categories\'] );
if( isset( $tax_selection[\'post_tag\'] ) && ( is_array( $tax_selection[\'post_tag\'] ) ) && ( !empty( $tax_selection[\'post_tag\'] ) ) )
$query->set( \'tag__in\', $tax_selection[\'post_tag\'] );
return;
}
front-page.php
<?php // Create and run custom loop
global $tax_selection; // use your variable
$custom_posts = new WP_Query();
$custom_posts->query( array(
\'post_type\' => \'topic\',
\'posts_per_page\' => 5,
\'category__in\' => $tax_selection[\'categories\'],
) );
while ($custom_posts->have_posts()) : $custom_posts->the_post();
?> <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="entry-left">
<h3><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( \'Permalink to %s\', \'twentyeleven\' ), the_title_attribute( \'echo=0\' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h3>
</div><!-- .entry-header -->
</article>
<?php endwhile; ?>
</div>