• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

My Monkey Do

A Log of Coding Solutions

  • Home
  • Web Hosts
  • Tools
  • About

WP Query inconsistencies in query

December 6, 2012 by Webhead

Problem

In WordPress, I created a new WP_Query with a few simple args to get a custom post type.  However, no results came back.  I could look at the query by checking WP_Query’s request property.  The query, when run in mysql returned the desired rows.  So what was happening to these rows?

 

Solution

WP_Query’s posts property holds all the posts that will be returned.  Looking into wp-includes/query.php, it turned out that I didn’t have read permissions.  I was trying to show private posts.  The user needed ‘read_post’ and ‘read_private_posts’ permissions (‘post’ can be replaced with your custom capability).

On a side note, tax_query does not work in the args if you are retrieving a single post object.  What determines this?  It depends on what args  you send WP_Query.  If you send it args like ‘name’, ‘p’, ‘page_id’, and some other parameters it will mark it as is_single and it will not perform tax_query!  This took me a while to find.

Filed Under: Coding Tagged With: php, wordpress

Primary Sidebar

Topics

apache apple block editor chrome cms css debug eCommerce embed firebug firefox git gmail goDaddy google hosting htaccess html html 5 IE crap image iPad iPhone javascript jquery linux localization mac os x ms sql mysql open source optimize php php 5.3 responsive rest api seo svg tinymce woocommerce wordpress wpengine xss yii youtube




Categories

  • Coding
  • Off the Shelf
  • Plugins
  • Random Thoughts
  • Server Stuff
  • Tools