I’m running into a strange issue on a site I’m working on. I have created a custom WP Query object to filter posts by their author, however I’m not seeing any results. If I take the author param out, I am seeing results but specifying an Author ID seems to return nothing.
I also noticed the issue on the Admin panel, when showing all posts, if I click on the Author name (which should filter the list to only show posts created by that author) I see ‘No Posts found’.
I’ve tried turning off all plugins and the issue still exists. I also tried re-installing WP core.
Here’s the custom query I’m using, although because I”m seeing the problem in the WP Admin side as well, the issue seems to be something else…
$myposts_query = array( 'posts_per_page' => '10', 'author' => 1 ); // The Query $the_query = new WP_Query( $myposts_query ); // The Loop if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); the_excerpt(); endwhile; endif;
I’m still having problems with this same issue. It seems anytime I try to use the parameter “author” anywhere on the site, I’m seeing broken results. Like the query returns nothing.
Noticed today that the Author template page is also not showing up (I get a 404) even though author.php is in the theme directory. I turned off permalink rewriting to check the query string, and sure enough it uses the same “author=…” syntax. Could this be an issue with a mislabeled table in the database?
I’m at a loss here…greatly appreciative of anyone that can point me in the right direction. Thanks.
strange problem. When no author id found, the same issue will happen. Are you sure the author id is 1? maybe you can try ‘author_name’ => ‘admin’ to see if it works.
<?php wp_reset_query(); ?>
I’ve checked the database, and in the posts table every post has an associated author ID – most say 1 (default super admin, which I’ve used to create most of the test posts), yet it doesn’t return results when I put this number into the custom query.
I was able to get it working using the ‘author_name’ parameter, but only for the admin account – other users still returned no results, even when I can see posts associated with their user ID in the database. I’d prefer to do the query on the user ID anyhow, in case the names change for whatever reason.
I’ve been using
<?php wp_reset_query(); ?>as well, but it doesn’t seem to make a difference. As I said originally, I’m also seeing the problem on the Admin Edit Posts table, which certainly shouldn’t be affected by any custom queries that I’ve written.
Can anyone direct me where to look in the WP core for the place that
author => 1gets translated into a SQL query? Because the db table seems to be fine, and the query is constructed correctly I assume there must be an issue with translating the custom query into an actual SQL call? Perhaps?
Okay, I’ve figured it out. Thought I’d post my troubleshooting process for anyone with the same issue:
I went back and disabled all plugins again, but this time I also reverted back to TwentyTen theme. Everything worked as it should. I activated BuddyPress, and still no issues. Then went back to my Theme and the issue came back – so obviously something wrong with my code (kinda my thought all along). I started looking in functions.php – deleted all the code, and no more problem.
After a quick search through functions.php for the keyword “author” (the assumed culprit) I found the issue. Because my site is about books, I had set up a Custom Taxonomy called Author with the slug “author”. Changed this and all is good 🙂
Lesson learned – stay away from obvious reserved names!
- The topic ‘Author parameter of WP Query not displaying results’ is closed to new replies.