admin管理员组文章数量:1315334
I had a query_post that worked, aimed lists only posts by author own, but now that I updated wordpress stopped working.
The query_post only works when you have only one author.
I updated WordPress 3.2.1. to 3.7.1
Index.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">←</span> Older posts', 'twentyten' ) ); ?></div>
<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</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’t here.', 'kubrick'); ?></p>
<?php get_search_form(); ?>
<?php endif; ?>
</div><br>
<?php get_footer(); ?>
I had a query_post that worked, aimed lists only posts by author own, but now that I updated wordpress stopped working.
The query_post only works when you have only one author.
I updated WordPress 3.2.1. to 3.7.1
Index.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">←</span> Older posts', 'twentyten' ) ); ?></div>
<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</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’t here.', 'kubrick'); ?></p>
<?php get_search_form(); ?>
<?php endif; ?>
</div><br>
<?php get_footer(); ?>
Share
Improve this question
edited Feb 8, 2019 at 23:57
fuxia♦
107k38 gold badges255 silver badges459 bronze badges
asked Dec 12, 2013 at 15:45
Wallace FerreiraWallace Ferreira
111 bronze badge
1 Answer
Reset to default 1Please don't use query_posts
. Just don't. Create a new query with WP_Query
.
Secondly, I am not sure how you are trying to use multiple authors in the query but I assume you are using author
and a comma separated string of IDs or author__in
and an array. For example:
$query = new WP_Query( 'author=2,6,17,38' );
// or
$query = new WP_Query( array( 'author__in' => array( 2, 6 ) ) );
http://codex.wordpress/Class_Reference/WP_Query#Author_Parameters
Either should work.
Also:
showposts
has been deprecated for a long time now. You should be using posts_per_page
. I also suspect that you should be using a filter on pre_get_posts
rather than creating a new query at all.
本文标签: query postsCoauthors plus problems with querypost
版权声明:本文标题:query posts - Co-authors plus problems with query_post 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741977372a2408203.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论