Inject Query Posts

Author:Scott Reilly
Version:1.0
Last update:18 Apr 2009
Compatibility:WP 2.3+, 2.5+, 2.6+, 2.7+
Comments:go here
Download:[ zip ]
Description:

Inject an array of posts into a WP query object as if queried, particularly useful to allow use of standard template tags.

Extended Description

Inject an array of posts into a WP query object as if queried, particularly useful to allow use of standard template tags.

WordPress’s template tags are intended to be used within ‘the loop’. The loop is managed by a WP_Query object which sets up various global variables and its own object variables for use by the various template tags. The primary purpose of a WP_Query object is to actually query the database for the posts that match the currently specified criteria. However, if you don’t need to query for posts since you already have them by some other means, you can still take advantage of the template tags by injecting those posts into the WP_Query via this plugin.

Depending on the template tags you are looking to use, or the logic you are hoping to employ within a loop, you may need to manually configure some of the query object’s variables.

Example:

[]czo0ODE6XCINCjw/cGhwDQovLyBTYXkgd2VcJ3JlIGluIHRoZSBzaWRlYmFyDQoNCi8vIFdlXCd2ZSBnb3R0ZW4gc29tZSBwb3N0IG9iantbJiomXX1lY3Qgb24gb3VyIG93bi4NCiRwb3N0cyA9IGMyY19nZXRfcmFuZG9tX3Bvc3RzKDUsIFwnXCcpOw0KLy8gSW5qZWN0IHRoZSBwb3N0cw17WyYqJl19CmluamVjdF9xdWVyeV9wb3N0cygkcG9zdHMpOw0KLy8gTm93IGxldFwncyBkaXNwbGF5IHRoZW0gdmlhIHRlbXBsYXRlIHRhZ3M6DQp7WyYqJl19aWYgKGhhdmVfcG9zdHMoKSkgOg0KICAgIHdoaWxlIChoYXZlX3Bvc3RzKCkpIDogdGhlX3Bvc3QoKTsgPz4NCg0KICAgICAgICA8bHtbJiomXX1pPjxhIGhyZWY9XCI8P3BocCB0aGVfcGVybWFsaW5rKCkgPz5cIiByZWw9XCJib29rbWFya1wiIHRpdGxlPVwiUGVybWFuZW50IExpbmsgdG97WyYqJl19IDw/cGhwIHRoZV90aXRsZV9hdHRyaWJ1dGUoKTsgPz5cIj48P3BocCB0aGVfdGl0bGUoKTsgPz48L2E+PC9saT4NCg0KICAgIDw/cGh7WyYqJl19cCBlbmR3aGlsZTs/Pg0KPD9waHAgZW5kaWY7ID8+DQpcIjt7WyYqJl19[]

Read the readme.txt.


Installation

  1. Unzip []czoyNzpcImluamVjdC1xdWVyeS1wb3N0cy12MS4wLnppcFwiO3tbJiomXX0=[] inside the []czoyMDpcIi93cC1jb250ZW50L3BsdWdpbnMvXCI7e1smKiZdfQ==[] directory for your site
  2. Activate the plugin through the ‘Plugins’ admin menu in WordPress
  3. Use the []czoyMDpcImluamVjdF9xdWVyeV9wb3N0cygpXCI7e1smKiZdfQ==[] function to inject an array of posts into a WP query object. Specify the posts array as the first argument. Configure the query object by passing an array as the second argument. If specifying a WP query object, pass it as the third object; if not specified then the global wp_query object will be assumed.

Template Tag

This plugin provides 1 template tag(s).

Function

[]czo2NjpcImluamVjdF9xdWVyeV9wb3N0cyggJHBvc3RzLCAkY29uZmlnID0gYXJyYXkoKSwgJHF1ZXJ5X29iaiA9IG51bGwgKVwiO3tbJiomXX0=[]

Injects posts into a WP_Query object.

Arguments

  • []czo2OlwiJHBvc3RzXCI7e1smKiZdfQ==[] : A single post or an array of posts to inject into a WP_Query object.
  • []czo3OlwiJGNvbmZpZ1wiO3tbJiomXX0=[] : (optional) Associative array of WP_Query variables to directly configure. Since the posts you are injecting weren’t processed via the typical WP_Query procedure, the state variables (is_archive, is_home, is_page, etc) will not have been set. Depending on the template tags you are using or what you’re trying to do, you may want to configure such variable. Any WP_Query variable is fair game and is blindly configured based on what you specify, so you should be familiar with WP_Query. You can specify the ‘query’ string to have it parsed via parse_query() which will configure many of the accordingly. e.g. specifying []czoyOTpcImFycmF5KFwncXVlcnlcJyA9PiBcJ3llYXI9MjAwOVwnKVwiO3tbJiomXX0=[] will cause the query object to set is_archive, is_date, and is_year to be true.
  • []czoxMDpcIiRxdWVyeV9vYmpcIjt7WyYqJl19[] : (optional) WP_Query object into which the posts should be injected. If null or not specified, then the global []czo5OlwiJHdwX3F1ZXJ5XCI7e1smKiZdfQ==[] will be used.

Release Log


Copyright & Disclaimer

Copyright © 2008-2009 by Scott Reilly (aka coffee2code)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.