合著者加上Query_POST的问题

时间:2013-12-12 作者:Wallace Ferreira

我有一篇query\\u帖子,它只列出作者自己的帖子,但现在我更新了wordpress,它停止了工作。

query\\u post仅在您只有一位作者时有效。

我更新了WordPress 3.2.1。至3.7.1

指数php

<?php $post_count = 0; ?>
<?php get_header(); ?>

<div class="page">
<?php if (have_posts()) : ?>
<?php 
    if ($user_level == \'1\'){ 
        global $current_user;
        get_currentuserinfo();
        query_posts("author=$current_user->ID&showposts=4&paged=$paged"); 
    } 
?>
<div id="main">
        <ul id="navigationMenu">
            <li>
                <?php $walker = new Menu_With_Description; ?>
                <?php wp_nav_menu( array( \'theme_location\' => \'content-menu\', \'menu_class\' => \'nav-menu\', \'walker\' =>  $walker ) ); ?>
            </li>
        </ul>
</div>
<div class="title-s">Posts</div>
        <?php while (have_posts()) : the_post(); ?>

            <div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
                <p class="contador-comentario">
                <?php comments_popup_link( \'0\', \'1\', \'%\', \'comments-link\', \'Comments are off for this post\');?>
                </p>
                <div class="title-s">
                <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__(\'Post: %s\', \'kubrick\'), the_title_attribute(\'echo=0\')); ?>"><?php the_title(); ?></a></h2>
                </div>
                <div class="resume">
                <?php the_excerpt() ?>
                </div>
            </div>
        <?php $post_count++; endwhile; ?>

<?php if ($post_count == \'0\' and $user_level == \'1\'){ 
        echo \'tour\';
        echo $post_count;
        } ?>    

        <div id="nav-below" class="navigation">
            <div class="nav-previous"><?php next_posts_link( __( \'<span class="meta-nav">&larr;</span> Older posts\', \'twentyten\' ) ); ?></div>
            <div class="nav-next"><?php previous_posts_link( __( \'Newer posts <span class="meta-nav">&rarr;</span>\', \'twentyten\' ) ); ?></div>
        </div><!-- #nav-below -->

        <?php else : ?>
        <h2 class="center"><?php _e(\'Not Found\', \'kubrick\'); ?></h2>
        <p class="center"><?php _e(\'Sorry, but you are looking for something that isn&#8217;t here.\', \'kubrick\'); ?></p>
        <?php get_search_form(); ?>
    <?php endif; ?>
</div><br>
<?php get_footer(); ?>

1 个回复
SO网友:s_ha_dum

Please don\'t use query_posts. 不要这样做。使用创建新查询WP_Query.

其次,我不确定您是如何尝试在查询中使用多个作者的,但我假设您正在使用author 和逗号分隔的ID字符串或author__in 和一个数组。例如:

$query = new WP_Query( \'author=2,6,17,38\' );

// or
$query = new WP_Query( array( \'author__in\' => array( 2, 6 ) ) );

http://codex.wordpress.org/Class_Reference/WP_Query#Author_Parameters

两者都应该有效。

此外:showposts 已经被弃用很长时间了。您应该使用posts_per_page. 我还怀疑你应该在pre_get_posts 而不是创建一个新的查询。

结束

相关推荐